For...Each not working

M

mark1

I don't understand why this won't clear the contents of
each sheet all at once. It only does the active sheet.
Help is appreciated.

Sub ClearMyCells()

For Each Worksheet In Workbooks

For Each c In [A1:D80]
If c.Interior.ColorIndex = 34 Then
c.ClearContents
End If
Next

Next

End Sub
 
F

Frank Kabel

Hi
use
Sub ClearMyCells()
dim wks as worksheet
dim c as range
For Each wks In worksheets

For Each c In wks.[A1:D80]
If c.Interior.ColorIndex = 34 Then
c.ClearContents
End If
Next

Next

End Sub
 
Top