IF statement based on background color

SeattleJim

New Member
Joined
Jun 4, 2007
Messages
20
Is it possible to use an IF statement when the logical test is testing whether a cell background color is one color or another?

For example, if A1 is "blue" do this... if it is "yellow", then do this... etc.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Not without a macro, no.

If the colors are set according to certain criteria, just write the IF statement to check for said criteria, not the coloring.
 
Upvote 0
How is the cell being coloured in the first place?

Manually or via conditional formatting?
 
Upvote 0
I dont know if there is a formula for that but you can use VBA:

Code:
Sub test()
    If Range("A1").Interior.Color = vbBlue Then
        'do this
    ElseIf Range("A1").Interior.Color = vbYellow Then
        'do that
    End If
End Sub

EDIT: I heard that in Office 2007 you can check background colors in formulas but not in previous versions.
 
Upvote 0
My spreadsheet uses both conditional formatting and data formatting. It works like a charm when users manually type in the information. But as soon as someone does a copy and paste, my main error catch routine doesn't work. The condition format still works (turns cell red when improper data is there). So instead of scanning over the spreadsheet looking for "red cells", there has to be an easier way to notify me when improper data has been copied to a cell.
 
Upvote 0
iggydarsa:
That won't check for Conditional Formatting colors.

SeattleJim:
Why not just do a check for the same condition?
What is your Conditional Formatting checking for and in what range?
 
Upvote 0
I have about 40 columns of data... ranging from dates to addresses to correct state abbreviations. My condition formats check for no commas in addresses to length of zip code of only 5. I get the feeling that I may be SOL since this all works when manually typed in. But when I did a copy and paste from another spreadsheet, that is when my main error check and data validation won't work.
 
Upvote 0

Forum statistics

Threads
1,214,959
Messages
6,122,476
Members
449,087
Latest member
RExcelSearch

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