Clear cell contents on all tabs in Workbook based on cell color

rach_oh

New Member
Joined
Aug 2, 2023
Messages
19
Office Version
  1. 2016
Platform
  1. Windows
Hi,

Trying to clear the contents of all cells that are Color #20 or RGB 204/255/255 that are on almost all tabs in various cells (manual colored)

Private Sub CommandButton3_Click()
Dim xcell As Range
Dim xrng As Range
Set xrng = ActiveWorkbook.Sheets
For Each xcell In xrng
If xcell.Interior.Color = RGB(204, 255, 255) Then
xcell.ClearContents
End If
Next
End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Hi @rach_oh
Welcome to the MrExcel forum. Please accept my warmest greetings and sincere hope that all is well.

Try this:
VBA Code:
Private Sub CommandButton3_Click()
  Dim sh As Worksheet
  Dim f As Range, r As Range
  Dim cell As String
  
  For Each sh In Sheets
    Application.FindFormat.Clear
    Application.FindFormat.Interior.Color = RGB(204, 255, 255)
    Set r = sh.UsedRange
    Set f = r.Find("", , xlValues, xlPart, , , False, , SearchFormat:=True)
    If Not f Is Nothing Then
      cell = f.Address
      Do
        f.ClearContents
        Set f = r.Find("", f, xlValues, xlPart, , , False, , SearchFormat:=True)
      Loop Until cell = f.Address
    End If
  Next
  Application.FindFormat.Clear
End Sub


--------------
Let me know the result and I'll get back to you as soon as I can.
Cordially
Dante Amor
--------------​
 
Upvote 0
Solution
I just ran another module and got this error from the code

1691083042445.png
1691083057291.png
 
Upvote 0
I just ran another module and got this error from the code
What do you mean by "another module"?

What changed in your book or on your sheet?

You could check what you had in your sheets in the execution of post #3 and now what you have in your sheets in the execution of post #4.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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