Results 1 to 3 of 3
  1. #1
    Plutonium Lounger Leif's Avatar
    Join Date
    Dec 2000
    Location
    U.K.
    Posts
    14,010
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Insert formula with code (2000+)

    Based on <post:=650,465>post 650,465</post:>, I came up with some looping code (where n = 1 and m = (n * 31) - 2):
    <code>
    strRange = "L" + CStr(m)
    Worksheets("C1").Range(strRange).Formula = "=SUM(L" + CStr((n * 31) - 24) + ":L" + CStr((n * 31) - 3) + ")"
    </code>
    which works inasmuch as the correct cell ends up with
    <code>=SUM(L7:L28)</code>
    but it remains as text rather than giving me the SUM total.

    If I click within the cell (to get into cell edit mode) and press return, I get the SUM result.

    What am I missing out?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Insert formula with code (2000+)

    Check the format of the cells in Format | Cells...
    Have they been formatted as text?

  3. #3
    Plutonium Lounger Leif's Avatar
    Join Date
    Dec 2000
    Location
    U.K.
    Posts
    14,010
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Insert formula with code (2000+)

    Aha! That was it. I was including formatting in the code but not until after I'd set the formula....

    Many thanks.

Posting Permissions

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