Best method for automatically changing an entire row's fill/font color based on one cell

dtarockoff

New Member
Joined
Jun 26, 2013
Messages
24
I have a master list of contact information that I color code by hand depending on a designation I give each row. The designation is just a single letter, "X" for example, and is listed under it's own column within each row.

In the example below, I'd want rows (not just the cells A1 and A3) 1 and 3 to have the same font color and fill color, which would automatically be adjusted based on the letter typed into column A. Row 2 would have a different font color and fill color but would also automatically be adjusted based on the "B" typed in A2.
-----A-----B-----C
1 X 1 2
2 B 1 2
3 X 1 2

Previously, I successfully did this with conditional formatting, by selecting the entire sheet and using a variation of the formula =COUNTIF($A1,"X"). I would use the "highlight cells" conditional formatting setting and just use a custom version of font colors and fills each time I made a new 'rule'. This has worked fine, but for some reason it won't work now that I've moved the data to a new sheet and reapplied the same rules.

Regardless, I think this is probably not the easiest nor most efficient way of doing this so I was wondering if anyone had any other ideas that didn't involve conditional formatting. Or, a better formula than the one I'm using in conditional formatting, maybe.

Thank you!
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Place this code in the code module for your worksheet (not into a regular module). You can add additional colors simply by adding more 'ElseIf' statements. Please let me know if this works out for you.
Code:
Option Compare Text
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("A:A")) Is Nothing Then Exit Sub
    If Target = "X" Then
        Target.EntireRow.Interior.ColorIndex = 3
    ElseIf Target = "B" Then
        Target.EntireRow.Interior.ColorIndex = 6
    End If
End Sub
 
Upvote 0
I appreciate the help, but I'm trying to avoid having to use VBA. Besides the fact that I'm a beginner when it comes to VBA, I have very specific colors I need to use that I don't know the "codes" for and I have over 10 letter combinations to assign colors to.
 
Upvote 0
If you send me the colors along with the letters associated with them and you are willing to give VBA a try, I'll be happy to update the macro for you. After that is done, all you have to do is the following:
-right click the worksheet tab
-click 'View Code'
-copy and paste the code into the empty code window that opens up
-close the code window
Now when you enter a letter in column A and exit the cell, that entire row will be colored automaticaly. That's it!
 
Upvote 0
For those interested, this is the code:
Code:
Option Compare Text
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("C:C")) Is Nothing Then Exit Sub
    Select Case Left(Target, 1)
    Case "A"
        Target.EntireRow.Interior.Color = 9737946
    Case "D"
        Target.EntireRow.Interior.Color = 5287936
        Target.EntireRow.Font.Color = vbWhite
    Case "H"
        Target.EntireRow.Interior.Color = 11851260
    Case "I"
        Target.EntireRow.Interior.Color = 14994616
    Case "M"
        Target.EntireRow.Interior.Color = 49407
    Case "O"
        Target.EntireRow.Interior.Color = 10213316
    Case "P"
        Target.EntireRow.Interior.Color = 65535
    Case "S"
        Target.EntireRow.Interior.Color = 255
    Case "T"
        Target.EntireRow.Interior.Color = 10498160
        Target.EntireRow.Font.Color = vbWhite
    Case "U"
        Target.EntireRow.Interior.Color = 2704713
        Target.EntireRow.Font.Color = vbWhite
    Case "G"
        Target.EntireRow.Interior.Color = 16777215
        Target.EntireRow.Font.Color = vbWhite
    End Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,981
Messages
6,122,566
Members
449,089
Latest member
Motoracer88

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