2

Can I use the SUM function to sum two or more columns in the same row?

Example:  
Column  : A B C D E  
Total   : 1 2 3 4 5
TotColAC: 4 6 (TotColBD)

Is it possible to use the SUM function or is there another way?

Thank you!

1
  • @@user2063626, do you know how to do it in vba? Commented Mar 3, 2013 at 4:57

1 Answer 1

7

Using VBA. It will add cells from A1 to E1. You can modify as per your requirement.

Sub Add()
    Dim totalAtoE As Double
    totalAtoC = WorksheetFunction.Sum(Range("A1:E1"))
End Sub

only A1 and C1

Sub AddAandC()
    Dim totalAandC As Double
    totalAandC = WorksheetFunction.Sum(Range("A1"), Range("C1"))
End Sub

as per your comment

Sub Add()

Dim lastRow As Long, i As Integer, totalAtoC As Double, FinalSum As Double
lastRow = Range("A5000").End(xlUp).Row

For i = 1 To lastRow
    totalAtoC = totalAtoC + WorksheetFunction.Sum(Range("A" & i & ":C" & i))
Next
FinalSum = totalAtoC

End Sub
Sign up to request clarification or add additional context in comments.

5 Comments

How do I get the sum of two columns that are separated by a column? Let say I want the sum of column A and column C without adding column B. Is it possible?
@yes totalAandC = WorksheetFunction.Sum(Range("A1"), Range("C1"))
I would like to use the lastRow variable into the range, how can I embed the variable in? let say the lastRow is 651 and I would like to put the add the sum of column A and column B in row 650 and put the result in row 651 but hard coding the number 561 into the range or declare lastRow = 651
Range("A" & lastRow).Value
@Jeannette Liu if you are happy with the solution please vote

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.