I am working on a vba code that places the sum of a column (F) dynamically at the bottom. I would like this formula to loop through the remaining columns in the worksheet up to column AM (E.g. Columns G,H,I etc.) How do you suppose I do this?
See my code below:
Sub SumColumns()
Dim LastRows As Long
Lastrows = ThisWorkbook.Sheets(“Sheet1”).Cells(Rows.Count, 5).End(xlUp).Row – 1
ThisWorkbook.Sheets(“Sheet1”).Range(“f” & Lastrows + 2) = Application.WorksheetFunction.Sum(ThisWorkbook.Sheets(“Sheet1”).Range(“f5:f” & Lastrows – 1))
End Sub