Apr 06 2021 06:01 AM
Hello Everyone,
I have written VBA code which is showing the AutomateSum.
1st question --- I want to show TOTAL SALES where total calculation has come in all sheet. Like -
2nd question --- I hide the NORTH RECORDS sheet, so when i run this code. So it gives error -
I click in DEBUG button, then it highlighted this line -
Please help.
Here is the attached file.
Apr 06 2021 07:13 AM
If you want to skip hidden sheets:
Public Sub AutomateSum()
Dim wsh As Worksheet
Dim LastRow As Long
Application.ScreenUpdating = False
For Each wsh In Worksheets
If wsh.Visible = xlSheetVisible Then
LastRow = wsh.Range("F1").End(xlDown).Row
wsh.Range("A" & LastRow + 1).Value = "TOTAL SALES"
wsh.Range("F" & LastRow + 1).Formula = "=SUM(F2:F" & LastRow & ")"
End If
Next wsh
Application.ScreenUpdating = True
End Sub
If you want to include hidden sheets:
Public Sub AutomateSum()
Dim wsh As Worksheet
Dim LastRow As Long
Application.ScreenUpdating = False
For Each wsh In Worksheets
LastRow = wsh.Range("F1").End(xlDown).Row
wsh.Range("A" & LastRow + 1).Value = "TOTAL SALES"
wsh.Range("F" & LastRow + 1).Formula = "=SUM(F2:F" & LastRow & ")"
Next wsh
Application.ScreenUpdating = True
End Sub
This code doesn't select cells, so it works for hidden sheets as well as for visible sheets.
Apr 06 2021 07:49 AM