Color cell based on a value

darrellx

New Member
Joined
Jan 28, 2006
Messages
5
I am making a spreadsheet comparing different quotes for building materials.

Is it possible to write a formula to color a cell a specific color when the value in a field is less than a value in another field. For example:

If value in cell b3 is less than cell a3, then color cell b3 yellow.

Thanks in advance.

darrellx
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
This can be done in vba but I'm not sure if it can be done using conditional formatting.

AMAS
 
Upvote 0
Hi,

You can use Conditional Formatting

Select B3
Conditional Formatting > New Rule > Format only cells that contain
Fill the boxes with the values below
Cell Value | less than | =A3
Format button
pick Fill ---> yellow
Ok, Ok

HTH

M.
 
Upvote 0
Please note that conditional formatting has a restriction on number of colors (at least in Excel 2003) to 3. If you need more colors, you can write a simple macro:

Code:
Sub add_colors_to_cells()

ActiveCell.Select
Do Until IsEmpty(ActiveCell) 'or any other criteria that indicates when the macro
                             'should stop coloring
    If ActiveCell < Range("A1") Then
        ActiveCell.Interior.ColorIndex = 6
    ElseIf ActiveCell >= Range("A1") And ActiveCell < Range("A2") Then
        ActiveCell.Interior.ColorIndex = 5
    'and so on
    End If
    ActiveCell.Offset(1, 0).Select
Loop

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,606
Messages
6,179,862
Members
452,948
Latest member
UsmanAli786

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