Thread: Summing rows
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
David David is offline
external usenet poster
 
Posts: 1,560
Default Summing rows

It appears it is always off one. Will it work to add this line below:
lr = cells(Rows.Count, i).End(xlUp).Row
lr = lr -1 (Added line)
It is a little difficult to see what you are trying to achieve, but I think
it is a set of sub totals below the data.

"Jeff Garrett" wrote:

I want to sum the integer elements from row 2 to row 9 inclusive, then
display it in a cell a couple rows below the last element, say row 14.
The trick though, is I am iterating through each column in the worksheet.

Sub SortEachColumn()
Range("A14") = "Best 8 Marks"
Range("A15") = "Total Possible"
Range("A16") = "Total Mark"
lc = cells(2, "iv").End(xlToLeft).Column
For i = 2 To lc
lr = cells(Rows.Count, i).End(xlUp).Row
Next i
End Sub

Notice in line 6, where it goes to the end (End(xlUp)), that is too far. I
only want from row 2 to row 9 inclusive, and then display the sum in row 14
of that column