Excel macro formula to sum column [Closed]

- - Latest reply:  sos - Jul 15, 2011 at 02:11 AM
Hello,

I need help with a macro please. I need a code to sum up Column E from line 3 to the end of the data. The formula needs to be in the cell row at the ended of the column but the problem is the end row various from report to report. The formula also need to substract the last line from the sum. The other consideration in the code is not all cells in Column E will have data in it

is the a code which can find the next empty cell after the last data cell in column E. Total from that point up to Line 3 but subtract the last data cell.

appreciate any help

See more 

1 reply

Best answer
Posts
1862
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
July 30, 2015
787
5
Thank you
suppose data is there from E3 to E12 you mean to sum E3 to E12 and subtract E12 which means sum E3 to E11.

so the macro will be

Sub test()
Dim r As Range
Set r = Range(Range("E3"), Cells(Rows.Count, "E").End(xlUp).Offset(-1, 0))
Cells(Rows.Count, "E").End(xlUp).Offset(1, 0) = WorksheetFunction.Sum(r)
End Sub

Say "Thank you" 5

A few words of thanks would be greatly appreciated. Add comment

CCM 5766 users have said thank you to us this month

thanks so much venkat1926. Code worked beautifully and exactly what I was after.

appreciate your kind help