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

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
15,488
Office Version
  1. 365
Platform
  1. Windows
Try
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
            With .FormatConditions(2).Font
            .TintAndShade = 0
            .Color = RGB(255, 0, 0)
            
            End With
        .FormatConditions(2).StopIfTrue = False
    End With
        
        
End Sub

Untested with live data but doesn't error like your original so hopefully works ok.
 
Upvote 0

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
15,488
Office Version
  1. 365
Platform
  1. Windows
Ok, now I'm having some unusual problems, I ran a test on this after posting and it worked, now I just tried it again, it works with a new file but not a saved one.

I'll have a look again see if I can find why it does that.
 
Upvote 0

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
15,488
Office Version
  1. 365
Platform
  1. Windows
Just out of curiosity, which version of excel do you have and which file extension on your workbook?

Seems to work ok for excel 03 files or if added to 07 xlsx type, but not excel 07 xlsm, which is even more confusing.
 
Upvote 0

iamtherascalking

New Member
Joined
Jan 30, 2009
Messages
8
I'm using 07, but its not saved at all; just a new workbook. It doesn't work if I save as xlsm or xlsx(and run from the xlsm) either.
 
Upvote 0

iamtherascalking

New Member
Joined
Jan 30, 2009
Messages
8
They work separately. If you isolate the top part and run it(with Cells.FormatConditions.Delete at the top), it works. Then isolate the bottom and run it(with Cells.FormatConditions.Delete at the top), it works.

But together they don't work. :confused:
 
Upvote 0

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
15,488
Office Version
  1. 365
Platform
  1. Windows
I found the same thing, but mine runs ok with the non xlsm files so that's the real confusing part.

Just to make sure I'm reading your formula and code right

You want column A bold if column B says Pass or Fail
And you want the row A:E red if B says fail or scrap ?
 
Upvote 0

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
15,488
Office Version
  1. 365
Platform
  1. Windows
neither, when it does work the results are dirrerent, it's red for pass and normal for the others, that's why i wanted to check before i try and correct it.

only just noticed that part of the problem.

But now for the ultimate error!

I just recorded a macro while setting the conditions manually, and even that gives error when it runs!

Excel doesn't like the macro it created!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,191,718
Messages
5,988,272
Members
440,146
Latest member
rgomes8

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
Top