Hi
The code below works with only one condition in the IF statement (the first one - Summary sheet).
However, when I add the other two sheet names that should NOT be cleared, it doesn't work?
Do I need to change something in the IF statement?
Thanks in advance.
Code that works:
Code that doesn't work:
The code below works with only one condition in the IF statement (the first one - Summary sheet).
However, when I add the other two sheet names that should NOT be cleared, it doesn't work?
Do I need to change something in the IF statement?
Thanks in advance.
Code that works:
Code:
Sub ClearSheets()
Dim sht As Worksheet
For Each sht In ThisWorkbook.Worksheets
If sht.Name <> "Summary" Then
sht.Cells.ClearContents
End If
Next
Exit Sub
End Sub
Code that doesn't work:
Code:
Sub ClearSheets()
Dim sht As Worksheet
For Each sht In ThisWorkbook.Worksheets
If sht.Name <> "Summary" And sht.Name <> "Sheet2" And sht.Name <> "Sheet3" Then
sht.Cells.ClearContents
End If
Next
Exit Sub
End Sub