Change cell font color to match text but is based on a formula

river

New Member
Joined
Jun 9, 2011
Messages
25
I have a workbook with two spreadsheets. One has a series of cells (say, A7:G7) that return a word ("Red", "Yellow", "Green", "Blue") based on a lookup table in the other worksheet with an array defined spanning (J2:L1006) that contains the words. The table array may be irrelevant. A dropdown option on the first spreadsheet determines the row in the array used to populate A7 to G7.

"All" I want to do is write vba code that will make the font color in A7:G7 match the word (e.g., "Red" will be in a red font, etc).

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Value = "Green" Then
Target.Font.ColorIndex = 4
End Sub
Doesn't seem to work. Neither does
Private Sub Worksheet_Change(ByVal Target As Range)
'Set Font Color based on Target cell's contents
Dim R As Range
For Each R In Range("J2:L1006")
With R
Select Case .Value
Case "Red"
Font.ColorIndex = 3
'and so on
End Select
End With
Next
End Sub
Help please!
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
If "Sheet1" Cell A1 has your dropdown list (the trigger event).

And "Sheet2" has the range you want to set the font.color

Put something like this in the "Sheet1" module.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Address = [COLOR="Red"]"$A$1"[/COLOR] Then
    
        'Set Font Color based on cell's contents
        Dim R      As Range
        For Each R In Sheets([COLOR="Red"]"Sheet2"[/COLOR]).Range("J2:L1006")
            With R
                Select Case .Value
                    Case "Red"
                        Font.ColorIndex = 3
                        'and so on
                End Select
            End With
        Next
    
    End If
    
End Sub

If you have Excel 2007 or later, you could do this with just Conditional Formatting.
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,600
Members
449,038
Latest member
Arbind kumar

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