For...Each not working

  • Thread starter Thread starter mark1
  • Start date Start date
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top