test cell for specific color & if true, change to no color...the code should work but it's not...

sadams1

Board Regular
Joined
Aug 19, 2006
Messages
219
hello & thank you for your consideration on this!

I'm just a hack that occasionally gets lucky finding something online & messing with it til it works & this seemed like a task that fit my skills but this code isn't changing a specific cell color to "no fill". Any insights would be greatly appreciated!



Sub TestFillColor()

Dim cell As Range

'Loop through each cell in selected range
For Each cell In Selection.Cells

'Test if cell has a fill color
If cell.Interior.ColorIndex = RGB(100, 100, 100) Then

'change to no fill
cell.Interior.Color = RGB(0, 0, 0)

End If

Next cell

End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
You are trying to test the ColorIndex (a number between 0 and 56) against the RGB(100,100,100) which is 6579300. Try changing ColorIndex to just Color your If..Then test.
 
Upvote 0
Solution
arrrgghhh...managed not to see that mismatch with "Color" & "ColorIndex". Now works like a charm! Thank you very much for the help!
This is my way of hacking away at a different result that I'd posted earlier in the week...the end result is pasting all colors not a light gray onto a table with alternating rows of light gray...like ledger paper. Was thinking that making the alternating rows as "light gray bar objects" would solve the problem of pasting the other colors but now the text looks "hazy" due to the gray object on top. Anyhow, can't thank you enough for your time.
Steve
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,583
Members
449,089
Latest member
Motoracer88

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