Conditional color coding in Excel

269 views Asked by At

I have a fairly simple question regarding Excel and VBA, but because I'm new to VBA, I have no idea how to implement it.

I have an entire column full of a color code. The cells in that column say either R, G, or Y.

I need a macro that will traverse that column, change all cells that say "R" to have a fill of red, change all cells that say "Y" to have a fill of yellow, and change all cells that say "G" to have a fill of green.

I know this can also be done by simply sorting the rows alphabetically and then changing the colors manually, but I am looking for an automatic way of doing that.

3

There are 3 answers

0
Michal Schmitt On BEST ANSWER

Highlight the column with your R, Y, and G and apply conditional formatting. | Home tab > Conditional Formatting > Highlight Cell Rules > Equal to... | Enter your letter of choice and select the corresponding color scheme!

3
exussum On

Just use conditional formatting. You can change both the text and the cell to be the same colour

0
Rapunzel Kath On

Please try this:

Range("A1").Interior.Color = RGB(0, 0, 0)`

For R = 0 To 255
    For G=0 To 255
        For B=0 to 255
    Cells(1 , 1).Interior.Color = RGB(R, G, B)`
Next R

You can use another loop change Cells row and column.