Results 1 to 4 of 4

Thread: Showing the formula in the cells

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2011
    Posts
    9

    Showing the formula in the cells

    I've written an assignment for uni using a couple of macros.

    However the way I've written them means that when they perform a calculation they do not leave any formulas in the cells.

    I had considered using the record macro tool but the calculation the sub performs has to be looped.

    Is there anyway i can change the sub below to show the formulas in the cells.

    John.



    Sub Forecast_Error()

    Sheets("model").Select

    Set myR = Range("C10")
    i = 0
    Do Until myR.Offset(i, 0).Value = ""


    myR.Offset((i + 2), 7).Value = (myR.Offset(i, 0).Value - myR.Offset(i,4).Value)

    i = i + 1
    Loop

    k = 12
    Do Until IsEmpty(Cells(k, 10))
    tot = tot + Cells(k, 10)
    k = k + 1
    Loop

    Range("J25").Value = tot / (k - 12)

    End Sub

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Showing the formula in the cells

    how about if you make the procedure into a custom worksheet function?
    this will still only show the formula as =myfunction(), not the workings
    as this procure appears to change values in many cells, it is probably not possible any way

    in most cases a formula can only affect the cell(s) containing the formula
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: Showing the formula in the cells

    I did not have enaugh time to analize your code to see exactly what it does but if what you want is to leave formulas on the sheet instead of values then try something like this:

    myR.Offset((i + 2), 7).Formula = "=C" & 10 + i & " - " & "G" & 10 + i
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2011
    Posts
    9

    Re: Showing the formula in the cells

    Thanks kalliman that worked great

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width