Email:      Pass:    Pass?
Subscribe for Free Excel tips & more!

Free Excel Forum

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


Similar Excel Video Tutorials

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
Highlight the Row and Column of the Selected Cell
- This macro will highlight the row and column of the active cell. This will fill the column and row of the active cell w

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 have a column of cells that are a mix of color filled and some that are not. On the same row as the colored cells I want to create an if statement that says something like, if the cell is filled with a color than copy its information to another cell. How do I make an if statement that can test for color fill?

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

How do I write an IF statement to change the fill color of a cell?

Example, I want the cell color to be white if the cell is empty, how do I write an IF statement for that?

+IF(A1="", "red") - I tried that, but the result is to put the word "red" in the cell instead.

What should I do?


I do not want a color change to occur if true, only if false

Sub breakout()
' breakout Macro
' Macro recorded 4/23/2003 by ak2101

ActiveCell.FormulaR1C1 = "=IF(RC[-5]=RC[-3],TRUE,IF(RC[-5]RC[-3],FALSE))"
Selection.Interior.ColorIndex = 35
End Sub


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.



Good Afternoon,

I have a IF statement that I need help with.

I am using this IF statement along with conditional formatting to highlight cells. Specifically, I need the cells to be filled in if the dates fall between a certain range

Please take a look at my example that have I attached.

For example, if you take a look at ROW 8 (Building 5), you will see that it does not correctly highlight the cells according to the IF statement. The Start Date is 5/15/10 and the End Date is 6/18/10. It is highlighting all of the cells before the date Start Date.

Here is the IF Statement:


=IF(OR(AND(Q$2>=$C4,Q$2<=$D4),AND(Q$2>=$E4,Q$2<=$F4),AND(Q$2>=$G4,Q$2<=$H4),AND(Q$2>=$I4,Q$2<=$J4), AND(Q$2>=$K4,Q$2<=$L4),AND(Q$2>=$M4,Q$2<=$N4),AND(Q$2>=$O4,Q$2<=$P4) ),"X","")

Simply, I need help in editing my forumla. The IF statement is working properly for ROW 4 - ROW 7. How do I change the forumla to work with the dates provided for ROW 8.

Thanks for you help in advance

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'm just trying to loop through all the worksheets in the workbook and if a particular fill color is present in a cell change the cell fill color to another color. I'm not receiving any errors but when I step through the code, it does not seem to be going through each cell in the range. If anybody can point out where I'm going wrong it would be much appreciated.

Please Login or Register  to view this content.