hi - I'm new to vba and I am trying to work out how to sum cells in each row via VBA.
Example: I want to sum values in columns A, B, and C for each row where the last row may vary and return the sum value in column D.
I've started with:
Sub Calculate()
Dim lastRow As Long
Dim i As Integer
Dim totalSum as Double
'where totalSum = A + B + C = D
lastRow = Range("A2").End(xlUp).Row
For i = 1 To lastRow
Range("D") = WorksheetFunction.Sum(Range("A" & i & "B" & i & "C"))
Next
End Sub
Could someone please help me fix this - it isn't working and I'm not sure how to fix. I have googled and check this forum but I can't seem to work it out.
Example: I want to sum values in columns A, B, and C for each row where the last row may vary and return the sum value in column D.
I've started with:
Sub Calculate()
Dim lastRow As Long
Dim i As Integer
Dim totalSum as Double
'where totalSum = A + B + C = D
lastRow = Range("A2").End(xlUp).Row
For i = 1 To lastRow
Range("D") = WorksheetFunction.Sum(Range("A" & i & "B" & i & "C"))
Next
End Sub
Could someone please help me fix this - it isn't working and I'm not sure how to fix. I have googled and check this forum but I can't seem to work it out.