Reefswaggie

New Member
Joined
Feb 13, 2015
Messages
10
Hi

I want to write VB code for an excel SS that searches for fill color and then performs an action based on that.
For instance, if the fill color is red, delete the cell or empty it
I use this code for coloring my cells:
With Sheet1.Range(Cells(xx, yy), Cells(xx + 1, yy)).Interior .ColorIndex = 15
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With

What I want to do now is write code that says:
if sheet1.cells(xx,yy) = .colorindex 15 then
sheet1.cells(xx,yy) = "NO!"
or whatever
i just tried that particular if then statement, and i got a syntax error.
I also tried: If Sheet6.Cells(xx, yy).ColorIndex = 3 Then
and i got an object does not support property or method this error message
is there a way to state it correctly?
thanks!
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Code:
if sheet1.cells(xx,yy).Interior.colorindex  = 15 then
If it workde putting the color in, why would you change it to verify that it is there? Also when putting it in, the default values for pattern and pattern color are not necessary. Those parameters only need be used it the pattern is other than solid. (just a space saving hint)
 
Last edited:
Upvote 0
If it workde putting the color in, why would you change it to verify that it is there?

i want to change it for other reasons not to verify that it is there...

for instance, there are uncolored cells that i want to find and empty - the only thing they have in common is their lack of fill
 
Upvote 0
If it workde putting the color in, why would you change it to verify that it is there?

i want to change it for other reasons not to verify that it is there...

for instance, there are uncolored cells that i want to find and empty - the only thing they have in common is their lack of fill

my reference is to the structure of the code, not your purpose in using it. the structure to enter a color is '[Range object].Interirior.CorlorIndex = [index #]'
That same structure is used to then look for cells that contain colors, modified to use the If statement, for example:
Code:
If ActiveSheet.Range("A2"}.Interior.ColorIndex = 3 Then
    'do something
End if
 
Upvote 0
thanks so much for your help JLGWhiz. I really appreciate it and am off to try it out now. and I always test on a new version so i can go back to the old version if i cannot undo my mistakes :) I learned that the hard way!
 
Upvote 0
thanks so much for your help JLGWhiz. I really appreciate it and am off to try it out now. and I always test on a new version so i can go back to the old version if i cannot undo my mistakes :) I learned that the hard way!

No problem,
Regards, JLG
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,893
Members
449,097
Latest member
dbomb1414

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