Consulting

Results 1 to 5 of 5

Thread: Syntax Help

  1. #1

    Syntax Help

    Hi,

    Cells(compLDR + 1, 6) = Application.WorksheetFunction.Sum(COMPR.Range("F3:F" & compLDR))
    The above code is working well. But if I want it to write it as below it is not working
    Cells(compLDR + 1, 6).Formula = " =Sum(COMPR.Range("F3:F" & compLDR))"
    As I am very much a starter in VBA I couldn't make it this.

    Any help is appreciated.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Cells(compLDR + 1, 6).Formula = " =Sum(F3:F" & compLDR & ")"
    [/vba]

    or

    [vba]

    Cells(compLDR + 1, 6).FormulaR1C1 = "=Sum(R3C:R[-1]C)"
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Hi xld,

    Cells(compLDR + 1, 6).Formula = " =Sum(F3:F" & compLDR & ")"
    This code is giving the result in the required cell as
    =Sum(F3:F8)
    instead of value.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Sorry, I copied your formula with ist space. Should be

    [vba]

    Cells(compLDR + 1, 6).FormulaR1C1 = "=Sum(R3C:R[-1]C)"
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    Thank you xld.

    Actually the R1C1 formula worked well for me. The problem was with the other one. But your explanation cleared me where I was doing mistake. It is the space in the formula.

    Have a good day.

Posting Permissions

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