Multiple Conditional Formatting and Color

iamtherascalking

New Member
Joined
Jan 30, 2009
Messages
8
What's wrong with the following?
It keeps getting caught at
Code:
.FormatConditions(1).Font.Color = RGB(255, 0, 0)
Code:
Sub Macro1()

    Cells.FormatConditions.Delete

    Columns("A:A").Select
    
    With Selection

        .FormatConditions.Add Type:=xlExpression, Formula1:="=OR($B1=""PASS"",$B1=""FAIL"")"
        
        .FormatConditions(Selection.FormatConditions.Count).SetFirstPriority

            With .FormatConditions(1).Font
                .Bold = True
                .Italic = False
                .TintAndShade = 0
            End With

        .FormatConditions(1).StopIfTrue = False

    End With

'=================================

    Columns("A:E").Select
    
    With Selection
    
        .FormatConditions.Add Type:=xlExpression, Formula1:="=OR($B1=""FAIL"",$B1=""SCRAP"")"
        
        .FormatConditions(Selection.FormatConditions.Count).SetFirstPriority

        .FormatConditions(1).Font.Color = RGB(255, 0, 0)
        .FormatConditions(1).Font.TintAndShade = 0

        .FormatConditions(1).StopIfTrue = False

    End With

End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I've tried editing the code in various ways, entering long code instead of using the With block, Color / ColorIndex.Defined red using RGB / vbRed / etc, with no success, same issue with every change.

Only thing I can suggest is maybe change the cell colour instead of font?

This code does that and hasn't tripped for me so hopefully if you can use this as an alternative, problem solved, otherwise I'm out of ideas.

Code:
Sub Macro6()
Cells.FormatConditions.Delete
    Columns("A:A").Select
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=OR($B1=""Pass"",$B1=""Fail"")"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Font
        .Bold = True
        .Italic = False
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    Columns("A:E").Select
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=OR($B1=""Fail"",$B1=""Scrap"")"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 255
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,454
Members
449,083
Latest member
Ava19

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