Hi.
Can anybody modify for me the code below so that the code will add the total sum of the last column underneath the last row? The code below works only for the last row in column "E", but I want the code to be flexible and detect the last column as well. Please note that my code also has an "auto fill down" which I would like to put in the last column as well.
Thanks in advance.
Sub Last_row_last_column()
Dim ws As Worksheet: Set ws = Sheets("Sheet1")
Dim LR As Long, rCell As Long
'misc
LR = ws.Range("A" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
'Part A
If IsEmpty(ws.Range("D18")) Then
ws.Range("D18").Formula = ""
ws.Range("E18").Formula = ""
End If
ws.Range("D18:E18").Resize(LR - 18 + 1, 2).FillDown
'Part B
For rCell = LR To 18 Step -1
If ws.Range("C" & rCell).Value = 0 Then
ws.Range("C" & rCell).EntireRow.Delete Shift:=xlUp
ElseIf ws.Range("C" & rCell).Value = "" Then
ws.Range("C" & rCell).EntireRow.Delete Shift:=xlUp
End If
Next rCell
With ws.Range("E" & LR + 1)
.Formula = "=SUM(E18:E" & LR & ")"
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.Font.Bold = True
.Font.Name = "Cambria"
.Font.Size = 8
End With
'Clean Up
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
Bookmarks