tanyaleblanc
Board Regular
- Joined
- Mar 16, 2019
- Messages
- 145
I'm looking to sum the column totals in column O to T and have the totals appears in Cell O1 to T1
=SUM(O2:O1048576)
If you use the formula I posted, which goes down to the last possible of Excel, it won't be an issue. Any blank cells to your sum is like adding zero. It won't change the value. And it is impossible to have anything past the last possible row of Excel, so you won't miss anything. Also, the advantage to this method is if you add more data, you don't ever need to adjust your formula (where if you have it just go down to the exact last row, you would need to re-run the macro code.I don't know what the last row is, this month is could be O3 to T3 and last row (last row could be row 6788 this month and next month it could be 7156).
As I mentioned, simply copy the the formula from O1 to cells P1:T1.I also want the totals to populate in cell O1 to T1
Sub MyTotals()
Dim cell As Range
Dim col As Long
Dim lr As Long
For Each cell In Range("O1:T1")
' Get column number of cell
col = cell.Column
' Find last row with data in that column
lr = Cells(Rows.Count, col).End(xlUp).Row
' Populate formula
cell.FormulaR1C1 = "=SUM(R[1]C:R[" & lr - 1 & "]C)"
Next cell
End Sub