Consulting

Results 1 to 2 of 2

Thread: Worksheet function Sum in Excel VBA

  1. #1

    Worksheet function Sum in Excel VBA

    Hi,

    I have query using worksheet function in excel vba, I have written the code, but Its not getting the results, I am looking some particular columns to do sum and output should be on desired column, since I will be updating the data in same columns in dayin & dayout, below is the example and code which I prepared.

    Example:-

    A1,B1,C1,D1,E1,F1 - ------ J1(sum of A1,c1,d1,f1)
    .
    .
    .
    .
    .
    A100,b100,c100,d100,e100,f100-------J100(sum of a100,c100,d100,f100)

    Code:

    [VBA]
    Sub Sum_Click()
    Dim lastrow As Long
    lastrow = Cells(Rows.Count, "A").End(xlUp).Row
    Range("J1:J" & lastrow).Formula = Application.WorksheetFunction.Sum(Range("a1:a" & lastrow), Range("c1:c" & lastrow), Range("d1:d" & lastrow), Range("f1:f" & lastrow))
    End Sub
    [/VBA]


    I would request any one of you to help me correcting this code.

    Thanks in advance.

    Regards
    GV Reddy

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

    Sub Sum_Click()
    Dim lastrow As Long
    lastrow = Cells(Rows.Count, "A").End(xlUp).Row
    Range("J1:J" & lastrow).Formula = "=SUM(A1,C1,D1,F1)"
    End Sub
    [/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

Posting Permissions

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