I need help simplifying this code. I need to find the last row with data based on column G, then need to sum and drag this sum formula across columns G:M. I am essentially trying to create a totals row.
It would be nice to also add a bold border above the row. I know this code is clunky, so need help simplifying. It would be great if it autodetected how many columns with data. Thanks in advance.
It would be nice to also add a bold border above the row. I know this code is clunky, so need help simplifying. It would be great if it autodetected how many columns with data. Thanks in advance.
Code:
Sub TotalRow()
Dim lastrow As Long
lastrow = Range("G8").End(xlDown).Row
Cells(lastrow + 2, "G").formula = "=SUM(G8:G" & lastrow & ")"
Cells(lastrow + 2, "H").formula = "=SUM(H8:H" & lastrow & ")"
Cells(lastrow + 2, "I").formula = "=SUM(I8:I" & lastrow & ")"
Cells(lastrow + 2, "J").formula = "=SUM(J8:J" & lastrow & ")"
Cells(lastrow + 2, "K").formula = "=SUM(K8:K" & lastrow & ")"
Cells(lastrow + 2, "L").formula = "=SUM(L8:L" & lastrow & ")"
Cells(lastrow + 2, "M").formula = "=SUM(M8:M" & lastrow & ")"
End Sub