ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Summing (https://www.excelbanter.com/excel-programming/318553-summing.html)

Teresa

Summing
 
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


Frank Kabel

Summing
 
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


"teresa" wrote:

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


Sharad

Summing
 
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Harald Staff

Summing
 
"Sharad" skrev i melding
...

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



Bob Phillips[_7_]

Summing
 
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



--
HTH

-------

Bob Phillips
"teresa" wrote in message
...
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




Sharad

Summing
 

Thanks Harald!


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


All times are GMT +1. The time now is 11:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com