Excel macro formula to sum column

Closed
sos - Jul 12, 2011 at 07:10 PM
 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

1 reply

venkat1926 Posts 1864 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 810
Jul 12, 2011 at 10:02 PM
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
5
thanks so much venkat1926. Code worked beautifully and exactly what I was after.

appreciate your kind help
0