Loop though a range and clear the contents of a cell which has an index color of 33

Sarah333

New Member
Joined
May 30, 2012
Messages
13
I have a data entry work book and i want to create a macro that loops through a range on F25:AA100 on each tab and clears the contents of cells with an index color of 33 only
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Something like:

VBA Code:
Sub ClearCellsColour33()
application.screenupdating = false
dim ws as worksheet
for each ws in activeworkbook.worksheets
dim cell as range
for each cell in ws.Range("F25:AA100").cells
   if cell.interior.colorindex = 33 then cell.value = vbnullstring
next cell
next ws
application.screenupdating = true
end sub
 
Upvote 0
Solution
Thank you for responding so quickly, I have modified your code a little as it wasnt running through the sheets, now it loops but does not clear the contents of the cell i have tried several options including writting a zero but nothing

Sub ClearCellsColour33()
'Macro to clear Input cells

'Application.ScreenUpdating = False

Dim ws As Worksheet
Dim a As Integer
Dim rng As Range, cell As Range

Set rng = Range("F25:F28")
a = Application.Worksheets.Count


For i = 1 To a
Worksheets(i).Activate

'For Each ws In ActiveWorkbook.Worksheets

For Each cell In rng
If cell.Interior.ColorIndex = 33 Then cell.ClearContents
Next cell
' Next ws
Next
'Application.ScreenUpdating = True
End Sub
 
Upvote 0
My code above does iterate through the sheets. The first version I posted didn't but I added it in within a minute or two - perhaps you got it before I added that part in?
 
Upvote 0
Glad we could help. :)
 
Upvote 0

Forum statistics

Threads
1,214,648
Messages
6,120,726
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top