English Accountant
New Member
- Joined
- Mar 18, 2021
- Messages
- 10
- Office Version
- 365
- Platform
- Windows
I am trying to clear nearly all the tabs on a spreadsheet, but when it gets to the last tab it I get the error message "Object variable or With block variable not set".
I am struggling to find a comparable example so any help would be gratefully received!
This is my VBA code:
I am struggling to find a comparable example so any help would be gratefully received!
This is my VBA code:
VBA Code:
Clear entire workbook
'
' Keyboard Shortcut:
'
Dim ws As Worksheet
Application.Goto Reference:="ClearAll"
For Each ws In ActiveWorkbook.Worksheets
If (ActiveSheet.AutoFilterMode And ActiveSheet.FilterMode) Or ActiveSheet.FilterMode Then
ActiveSheet.ShowAllData
End If
'ActiveSheet.ShowAllData
Range("A16:E215").Select
Selection.ClearContents
Range("G16:H215").Select
Selection.ClearContents
Range("K16:M215").Select
Selection.ClearContents
Range("A16").Select
ActiveSheet.Next.Select
Next
End Sub