Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding the cells of a column

Status
Not open for further replies.

meghaAgrawal

Programmer
May 20, 2004
14
US
I need to add a number of cells. They all are in the same column. I have row numbers and column number values stored in integer variables. I want to store their sum in a new variable, say total. Following does not work - please advise how should I do it

total = SUM(cells(rowStart, col), cells(rowEnd, col))

Thanks!
 
Something like this ?
For r = rowStart To rowEnd
total = total + Cells(r, col).Value
Next r
You may also take a look at WorksheetFunction

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Yes thats one solution. But I want to avoid the loop. Like how it happens in formula - where we can specify the cell range. The only problem is my cell range is determined at run time and I cannot harcode something like sum(A2:A8). Whatever I have is in variables.
 
Something like this ?
total = Application.WorksheetFunction.Sum(Range(Cells(rowStart, col), cells(rowEnd, col)))



Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Perfect! That's what I was looking for - thank you very much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top