dakkat
02-02-2011, 03:06 PM
Hello,
I have written the following code and it works but only for the active worksheet. I want the code to cycle through all worksheets. If I make a worksheet active (by clicking the tab) and run the macro it works for that active worksheet. There are hundreds of worksheets. Can someone help me with why it is not looking at all worksheets? What am I missing?
Sub ClearExc()
Application.ScreenUpdating = False
Dim sh As Worksheet
For Each sh In Worksheets
If LCase(sh.Name) <> "admin" Then
If InStr(Range("D4").Value, "@") Then
Range("A120:I500").Select
Selection.ClearContents
Range("A120").Select
End If
End If
Next
Application.ScreenUpdating = True
End Sub
I have written the following code and it works but only for the active worksheet. I want the code to cycle through all worksheets. If I make a worksheet active (by clicking the tab) and run the macro it works for that active worksheet. There are hundreds of worksheets. Can someone help me with why it is not looking at all worksheets? What am I missing?
Sub ClearExc()
Application.ScreenUpdating = False
Dim sh As Worksheet
For Each sh In Worksheets
If LCase(sh.Name) <> "admin" Then
If InStr(Range("D4").Value, "@") Then
Range("A120:I500").Select
Selection.ClearContents
Range("A120").Select
End If
End If
Next
Application.ScreenUpdating = True
End Sub