Summing

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have three columns of data and 100 rows,
I want the 4th column to sum each row,
the code I have is as follows:

Think there is something wrong with my SUM Function


Dim i, j

For i = 1 To 100
Cells(i, 4) = Sum(Cells(i, 1), Cells(i,3))
End Sub
 
Hi
why do you want a macro for this and don't insert the formula in the cells
directly and copy this formula. so something like
=SUM(A1:C1)
and copy this down
 
Hi,
Change it to following:

For i = 1 To 100
Cells(i, 4) = Cells(i, 1) + Cells(i, 2) + Cells(i,3)

You cant use that Sum function in VBA.

Sharad
 
You cant use that Sum function in VBA.

Hi Sharad

Be very careful with "cant" when it comes to Excel / VBA.

Sub Test()
MsgBox Application.Sum(Range("A1:A10"))
End Sub

HTH. Best wishes Harald
 
SUM is a worksheetfunction, and you are trying to use it VBA. You can either

- use a straight worksheet function of SUM, no V BA
- use a worksheetfunction in VBA - Cells(i, 4) =
WorksheetFunction.SUM(Range("A"& i & ":C" & i))
- add in V BA - Cells(i, 4).Value = Cells(i, 1).Value + Cells(i,2).Value +
Cells(i,3).Value
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top