VBA Conditional Formatting Colors

Littlemalky

Board Regular
Joined
Jan 14, 2011
Messages
223
I'm super confused. So i have my code set up that I pretty much just adjusted from the recorder macro with the exact color reference that the recorder created, however, when I run my macro with that same color number it gave me, it breaks and doesn't recognize it. Does anyone know how to make my font red? This is what I have:
Code:
LastRow = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count
    Range("E2:E" & LastRow).FormatConditions.Add Type:=xlTextString, String:="D-", TextOperator:=xlBeginsWith
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Font
        .Color = 3
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Oops, I apologize the number that the recorder gave me was "-16776961", not 3, 3 is the alternative I tried, but didn't work.
 
Upvote 0
Hi,

Try this

Code:
Sub Test1()
    Dim lastRow As Long
    
    With ActiveSheet
        lastRow = .Cells(.Rows.Count, "E").End(xlUp).Row
        
        With .Range("E2:E" & lastRow)
            .FormatConditions.Add Type:=xlTextString, String:="D-", TextOperator:=xlBeginsWith
            .FormatConditions(.FormatConditions.Count).SetFirstPriority
            With .FormatConditions(1).Font
                .ColorIndex = 3
                .TintAndShade = 0
            End With
            .FormatConditions(1).StopIfTrue = False
        End With
        
    End With
   
End Sub

HTH

M.
 
Upvote 0

Forum statistics

Threads
1,224,565
Messages
6,179,549
Members
452,927
Latest member
rows and columns

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