#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 123
Default 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!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default 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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default 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





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 123
Default Summing


Thanks Harald!


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

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
summing captsamm(remove)@comcast.net Excel Discussion (Misc queries) 4 December 11th 09 05:38 PM
summing Catherine Excel Worksheet Functions 3 June 6th 07 04:28 PM
PivotTable and summing/not summing ~*Amanda*~[_2_] Excel Discussion (Misc queries) 1 March 14th 07 07:35 PM
Summing No Name Excel Programming 5 June 15th 04 11:36 PM
summing ChrisG[_4_] Excel Programming 2 September 22nd 03 11:13 PM


All times are GMT +1. The time now is 12:25 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"