Close Window   
Free Ebook
Get Your Free Excel
Our Top 15 Excel Tutorials
Instant Access!
Subscribe for Free Excel tips & more!

If Statement To Change Cell Fillcolor

Forum Register
Search Excel Forum Posts, Tutorials, Macros, Tips, and More

Hi All

Is it possible to use an IF statement to change a cells fills color? I am wanting to change a cells fill color if my IF statement is true, and if false then make it nofill.

Thanks for any assistance


View Answers     

Similar Excel Tutorials

Break out of or Exit Different Types of Loops in VBA Macros in Excel
How to Exit, End, or Break out of loops in Excel. This tutorial includes breaking out of While, Do, and For loops. ...
VBA IF Statement in Excel Macros
IF statements allow you to make decisions in your Macros and VBA in Excel. An IF statement gives you the power to ...
Increment a Value Every X Number of Rows in Excel
How to increment a value, number, percent, etc. every so many rows in Excel. This tutorial teaches you how to build ...
OR Function - Check if Any Argument is True
The OR function in Excel checks if ANY argument in it evaluates to TRUE.  If anything evaluates to TRUE, then the f ...

Helpful Excel Macros

Determine a Cell's Color with this UDF - Outputs as Text or the Index Number in Excel
- This free Excel UDF allows you to output the color of a cell in text format or as that color's index number. Also note
Highlight Cells with Text or Formulas (non-empty cells)
- This macro will highlight all cells in excel which are not empty. This means that if a cell contains formulas, text, nu
Highlight Every Other Row in a Selection in Excel - Table Formatting
- This free Excel macro will highlight every other row in a selection of cells with a color that is specified within the m
Highlight the Row of the Selected Cell
- This macro will highlight the row and column of the active cell. This will fill the row of the active cell with a solid
Automatically Highlight the Active or Selected Cell
- This macro will highlight the active cell in any excel spreadsheet with a color selected in the code. This means that a

Similar Topics


I need to make certain cells change color when a text string is true.

ie my formula in the conditional formation box is:


When the above statement is tru I expect the cell top change color as I've formatted it that way. However the statement above doesnt work as the cell never changes color.

I think I may be missing something obvious. Anyone able to see what the problem is with the above AND statement?


Hello all,

I would like to be able to change the color of a cell when a specific
value is attained. E.g. If the statement 1+1=2 is TRUE then make the
cell where the 2 is, Green. If the statement is FALSE then change the
color to red.

Thank you in advance

Trying to change the color of the results generated from a if:then,
true/false logical statement with in a formula. I would be happy if I could
change the format of the cell using a information formula
(=isnumber():color,34) or something like this. The goals is not to use the
format menu from the tools bar, but to automat this action. I am trying to
avoid using a macro, which again would require an action on the tool bar.
Thank you for any tips, GREG


I am currently try to have cells change color according to their value. I was wondering if there was a way to do this by using an "if" statement. I am aware of conditional formatting, but I cannot copy and paste this formula so I would prefer to use an if statement.

For example, I have a value in "A2", and if "A2" is >= "B2" then it is green, if it is >="C2" and <="B2" then it is yellow and if it is <="C2" it is red.

The values of C2 and B2 change depending on demand. Is there a way to use an if statement to do this?

Thank you!

Hey everybody. Trying to get multiple conditional formats (which I'm using a select case statement) but have to be able to use wildcards. Anyone know how? I'm wanting to change the color of a cell based on the first word in the cell (Test *) (Empty *) that sort of thing. Now I think a left statement would work, but I don't know how to code it to change background color. Any help would be awesome.

I was wondering if I could do a IF/Then statement with a font color change and simple calculation. Example, if I wanted to divide Cell B1 by Cell A1 and place the answer in Cell C1. If that number is 51% or higher make it blue, 49% or lower make it red, 50% stay black. I have done simple if/then statements where I would use seperate cell to say yes or no, but I was wanting to try to find a way to put the formula in C1 to both divide B1/A1 but also change the color of the font depending on the answer.

Is this possible??



I'm try to change the cell background color within a function a long with an output from the function. Here is a simple code I've tried.

Function changeColor(name, num)

If (num < 1) Then
fillColor = 1 ' black
fontColor = 2 ' white
ElseIf (num >= 1 And num < 3) Then
fillColor = 3 ' red
fontColor = 2
ElseIf (num >= 3 And num < 5) Then
fillColor = 45 ' orange
fontColor = 1
ElseIf (num >= 5 And num < 7) Then
fillColor = 6 ' yellow
fontColor = 1
fillColor = 4 ' green
fontColor = 1
End If

Selection.Interior.ColorIndex = fillColor
Selection.Font.ColorIndex = fontColor

changeColor = name

End Function

I have tried doing this multiple ways. The example above is to show what im trying to do. Its almost like the conditional formatting but im changing the color of the cell based on the value of another cell.

Is there a way to use a formula to color a cell??? I have an IF statement that if true, I want the cell to formatted a color (any color, yellow, blue whatever). And if the statement is false then I want it to stay grey.

Can this be done or do I have to do this with VBA???

Thanks in advance for the help!!!

First of all, I'd like to apologize if this has already been covered.
I did a search and I've found some things that help, but I think I need a more detail explanation.

I'm trying to change the color of an Autoshape with VBA.
However, I can't seem to make the color change without first selecting the object.

I believe I have to do a "Set" statement.

Which brings me to my next question.
Can someone help me understand how to use a "Set" statement and how it works?

Again my apologies if this is a bother.

I am look to have the color of specific cells change as based on an if statement. I tried using conditional formating but the data I would like the if statement to use is located on another page of the worksheet and thus conditional formating will not work. I'm thinking I have to use Visual Basic but I have no idea where to start with the code. Just wondering if someone could help me out. Thanks


I use excel 2007 and have created a heat map on 3 color scale with red fill highlighting the areas of concern, but the text (black color) is not clearly visible in red fills. Is it possible to change the text color to 'white' using an excel function or VBA code? I tried to find the color of cells but have been unable to do so using VBA as the cells are conditionally formatted (due to heat map).
It is not possible for me to change the color coding of cells.


Hi everyone,

I have a tedious task of highlighting and changing the fill color of certain cells. There is a specific pattern that needs to be changed everytime.

Since the color is always consistant throughout the certain cells, I would like to make 1 cell be the master cell and every other cell in my pattern copy the color fill of the master.
Therefor if I change the color of the master cell, every other cell in the pattern would automatically change itself to the same fill color.

Would there be a general solution to this with an equation or would it involve writing a macro for it.

Thanks in advance

I am trying to use the Conditional Formating tool to change the color of an item in the column if it is not blank. I would like it to do a test to see what color or "text" is in the heading box to control what color the cells will change to. I am using this statement, which is probably flawed.

=IF(C1="Remediation Plan Pending",1,0)(ISNUMBER(C2:C14),1,0)

Please see attached sample, it will probably make more sense. I was also trying to use an array so the columns would automatically change but I am having to edit every conditional format box and change the range.

I am using an IF statement and would like to change the cell color for one condition. Can someone help me?

(I want to change the blank cell to a new color)

Also, how do I change the font color in a cell using the IF statement.
=IF(E15*1000000000000>1000,"Red text","Green text")
I would like the "Red Text" to be red, and so forth.



I've created a conditional formatting with 3 rules. I need a cell to color fill based on the difference from the cell to the left of it.

For example:
cell g26 is selected
cell value = f26 format YELLOW fill
cell value > f26 format GREEN fill
cell value < f26 format RED fill.

As soon as I click appy, g26 color fills RED because at this point, the cell is empty and f26 is 4.

How can I make the color fill change based on the value when I change it? It stays RED in this example.

Part two would be I need to do this for my entire it just drag to fill from there?

Thanks so much!

Im trying to find what If statement or any kind of statement will look at the worksheet tab color and tell me what color it is. Depending on what color it is i will fill the cell with different results "incomplete, complete, needs revision". Is this possible?? Thanks.

heres what i want to do...

assign/fill cell b2 with a specific color
assign/fill cell d2 with a different color
assign/fill cell f2 with another

select a group of cells (b4-b7) and while selected, be able to then click cell b2 and the color of the selected cells will change to whatever color i have designated in cell b2.

i am trying to make a user friendly type of timeline spreadsheet where the user can just select a group of dates along the timeline and color them without having to look for the matching color in the color picker. i will have red, green, blue, and no fill, so if the dates change they can "erase" them with no fill.

in essance the colored cells would just be shortcut "buttons" they would not have any editable type or function to them

make sense? i just need to know the process, but a sample code (if necissary) would be appriciated

How do I write a formula to change the font color or even cell color using a formula from another cell?

I know how to write a IF statement, just don't know how to tell Excel to make the necessary changes.

I'm doing a time sheet/schedule for my wife, yes I know I could probably download one, but I would rather do my own for the sake of learning. Anyhow the basic layout is done, and now I'm trying to write formulas to make everything work. Of course my knowledge with excel formulas is limited, so that is why I'm here.

I would like to write a IF condition that if true would change the font color or background cell color (really just anything to make that cell standout but not change actual data within cell).

Her scheduled hours consist of using the first row and the actual hours she works she enters on the second row directly beneath it. So if she enters hours later than scheduled for a particular day (shes late!) then that cell will be made to standout.

F13 = 8:30 AM <-- Scheduled Time
F14 = 11:00 AM <-- Actual Time (Yeah I know shes real late, probably fire her *** )

So since she has to input her time for that cell, I can not put a formula in that cell for obvious reasons. So I have to execute a formula from within another cell, and then tell it to modify the F14 cell if F14 is greater than F13.

Now this is all I really need, but for the experts out there, you can read on if you like.

Now the above is only for one day of the week, which I have each work week dedicated to a row like so:
(After posting I noticed all my formatting was removed, so the following is all squashed together. I only had spacing, no fancy formatting.

F G H I J K ----> up to W
12 P/F 5/16 HRS P/F 5/17 HRS .....
13 8:30 AM 5:00 PM 8.00 8:30 AM 5:00 PM 8.00 ......
14 11:00 AM 5:00 PM 6.00 8:30 AM 5:00 PM 8.00 .......
(Week 2)
15 P/F
16 8:30 AM
17 8:30 AM

So if the IF statement can be made into an array to handle the entire row that would be awesome, but if not I as I said earlier I can get by. Just would be nice to have one formula for a row instead of 7 formulas taking up 7 cells

I hope that makes sense, I tried to break it down as much as possible

Thanks in advance


Instead of having to use the drop down menu of colors to select the fill color, I would like to have a macro that does the following:
1. First, before executing the macro, select a cell from a group of cells that already have different color fills.
2. Run the macro (click on the button assigned to the macro)
3. The macro would detect the color of the cell that had been selected and change the color of the Fill-Color command button to that color.

Now, any cell selected can be changed to the desired color by just clicking the Fill-Color command button without having to use the menu of colors.



Im not sure if this is even an option but I though I would ask.
I am currently laying out a Budget and would like the amount remaining to be green if it is greater than 1 and red if less.

So the if statement would look something like:

(if f12>1, color Green, color red)

I am not sure if this is even an option. If anyone could shed some light on this I would really appreciate it, thank you very much.

I am trying to write a formula that will check to see if a certain cell or named group of cells contains certain data using an if/else statement.

Something like:

=IF(A2="03", ....

If statement returns true, then write a new value to the tested cell
If statement returns false, do nothing.

This would be easier if the statement was in the cell that would hold the data, but unfortunately it can not.

Any help would be greatly appreciated.


I am trying to format an excel sheet so that when a specific cell changes color, so does another group of cells. However, I do not want all cells in the group to change color, only the ones that have data entered. For example, if cell A1 is the independent cell, changing its color will change the color of all cells A2:A10, but only for the ones that have something entered in, leaving the rest as no-fill. Furthermore, I would like it so that if I enter data in any of the cells in the group (A2:A10) that it will automatically change color to be the same as cell A1.

To summarize, I pretty much want the group to act as though it is conditionally formatted for non-blank cells, while responding to the color of one particualr cell. Is this possible and, if so, how can I do it?


Hi Guys,

Was wondering how i make an IF statement only change the value of the cell when the condition is met, and to leave it unchanged when the condition is false.

Thanks in advance.

I am using Office 2007 and have successfully used the Cells.Interior.Color to change cells fill color. I would like to be able to undo these changes. Depending on the data entered I am changing the color but I may need to change it back to white. When I use the Cells.Interior.Color = vbWhite the cell fill changes to white but the cell border is gone .

Is there a way undo the color change and have the cell border show up?


So I am trying to create an if statement that checks if the sum of cells B2 through F2 is less than or equal to 2, then Small should be there, and if it is greater then 2 then Large should. And then, I want to conditionally format the cell so that if it is false, then that cell turns red, otherwise nothing. I have attached an excel file with a sample data set. Any assistance would be greatly appreciated. Thanks.