Excel macro formula to sum column [Closed]

 sos -

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

1 reply

Registration date
Sunday June 14, 2009
Last seen
July 30, 2015
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
Thank you

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

CCM 3257 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