Delete text if fill in color is different from light grey (instead of yellow)

Nick70

Active Member
Joined
Aug 20, 2013
Messages
299
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have a code that deletes text in a set range if the fill-in color is different from yellow (see below).

I would like to change criteria so that text is deleted if fill-in color is different from light grey (not grey but light grey).

I know there are many light greys but let's just choose one.

How would the code change (i.e from vbYellow)?

VBA Code:
VBA Code:      
Dim c As Range, rng As Range

For Each c In Sheets("Sheet1").Range("B5:E100")
If c.Interior.Color <> vbYellow Then
If Not rng Is Nothing Then
Set rng = Union(rng, c)
Else
Set rng = c
End If
End If
Next
If Not rng Is Nothing Then rng.Clear

Thanks,
Nix
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Select a cell with the gray you want & run
VBA Code:
Sub chk()
MsgBox ActiveCell.Interior.Color
End Sub
Then just replace vbYellow in your code with the number from the message box
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,861
Messages
6,121,973
Members
449,059
Latest member
oculus

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