LtCmdrData
Board Regular
- Joined
- Jan 24, 2018
- Messages
- 58
- Office Version
- 365
- Platform
- Windows
Hello,
I'm getting the error above when I try to run a macro to clear a report and reset things for the next time. Specifically it is supposed to unhide a sheet, turns off the advanced filter so the contents can be cleared, and hide the sheet again. I am running Excel 2016 on Windows 10. The If Then Statement below in red is what is coming up as the error. Can anyone tell me why I am getting this error and how to fix it? Thanks! Here is the code:
Sub ClearContents()
'
' ClearContents Macro
'
Dim lrow As Long, ws As Worksheet
Set ws = ThisWorkbook.Sheets("Filter")
lrow = ws.Range("A" & Rows.Count).End(xlUp).Row
'
Cells.Select
Selection.ClearContents
Range("A1").Select
Sheets("Filter").Visible = True
Sheets("Filter").Select
If ActiveSheet.FliterMode Then ActiveSheet.ShowAllData
Range("A6:J" & lrow).Select
Selection.ClearContents
Range("A6").Select
Sheets("Filter").Visible = False
I'm getting the error above when I try to run a macro to clear a report and reset things for the next time. Specifically it is supposed to unhide a sheet, turns off the advanced filter so the contents can be cleared, and hide the sheet again. I am running Excel 2016 on Windows 10. The If Then Statement below in red is what is coming up as the error. Can anyone tell me why I am getting this error and how to fix it? Thanks! Here is the code:
Sub ClearContents()
'
' ClearContents Macro
'
Dim lrow As Long, ws As Worksheet
Set ws = ThisWorkbook.Sheets("Filter")
lrow = ws.Range("A" & Rows.Count).End(xlUp).Row
'
Cells.Select
Selection.ClearContents
Range("A1").Select
Sheets("Filter").Visible = True
Sheets("Filter").Select
If ActiveSheet.FliterMode Then ActiveSheet.ShowAllData
Range("A6:J" & lrow).Select
Selection.ClearContents
Range("A6").Select
Sheets("Filter").Visible = False