VBA Condtional Format Assistance

keef2

Board Regular
Joined
Jun 30, 2022
Messages
185
Office Version
  1. 365
Platform
  1. Windows
Hey there:

Conditional Format Code is working for each condition individually, but not if both are conditions are met. If both Conditions are met the only issue is column L doesn't highlight yellow:
VBA Code:
'Conditional Format for ChiResident & Apprentice
Dim Cond1 As FormatCondition, cond2 As FormatCondition
Set Cond1 = Range("L" & bot_row).FormatConditions.Add(xlExpression, xlEqual, EmployeeInformation.ChiResident.Value = True)
Set cond2 = Range("L" & bot_row & ":AB" & bot_row).FormatConditions.Add(xlExpression, x1equal, EmployeeInformation.Apprentice.Value = True)
With Cond1
.Font.Color = vbRed
.Font.Bold = True
End With
With cond2
.Interior.Color = vbYellow
End With

I have tried a few ways to get this to work if both conditions are met but cannot get this to work appropriately. Any help is much appreciated here are my attempts:

Attempt 1:
VBA Code:
  With Cond1 And Cond2
Range("L" & bot_row).Font.Color = vbRed And .Font.Bold = True And .Interior.Color = vbYellow
Range("M" & bot_row & ":AB" & bot_row).Interior.Color = vbYellow
End With

Attempt 2:
VBA Code:
If Cond1 And Cond2 = True Then
Range("L" & bot_row).Font.Color = vbRed
Range("L" & bot_row).Font.Bold = True
Range("L" & bot_row).Interior.Color = vbYellow
Range("M" & bot_row & ":AB" & bot_row).Interior.Color = vbYellow
End If

Attempt 3:
VBA Code:
    'Conditional Format for ChiResident & Apprentice
Dim Cond1 As FormatCondition, Cond2 As FormatCondition, Cond3 As FormatCondition
Set Cond1 = Range("L" & bot_row).FormatConditions.Add(xlExpression, xlEqual, EmployeeInformation.ChiResident.Value = True)
Set Cond2 = Range("L" & bot_row & ":AB" & bot_row).FormatConditions.Add(xlExpression, x1equal, EmployeeInformation.Apprentice.Value = True)
Set Cond3 = Range("L" & bot_row).FormatConditions.Add(xlExpression, xlEqual, EmployeeInformation.ChiResident.Value = True) And Range("M" & bot_row & ":AB" & bot_row).FormatConditions.Add(xlExpression, x1equal, EmployeeInformation.Apprentice.Value = True)
With Cond1
.Font.Color = vbRed
.Font.Bold = True
End With
With Cond2
.Interior.Color = vbYellow
End With
With Cond3
Range("L" & bot_row).Font.Color = vbRed
Range("L" & bot_row).Font.Bold = True
Range("L" & bot_row).Interior.Color = vbYellow
Range("M" & bot_row & ":AB" & bot_row).Interior.Color = vbYellow
End With
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
After running your code (and setting the rules), when you look at the Conditional Formatting Rules Manager window, does one of the rules have the Stop If True checkbox checked? That might explain it.

1662996720960.png
 
Upvote 0
Solution
After running your code (and setting the rules), when you look at the Conditional Formatting Rules Manager window, does one of the rules have the Stop If True checkbox checked? That might explain it.

View attachment 73727
Thanks! Thats exactly what it was. Here is updated code to take care of this:
VBA Code:
Dim Cond1 As FormatCondition, Cond2 As FormatCondition
    Set Cond1 = Range("L" & bot_row).FormatConditions.Add(xlExpression, xlEqual, EmployeeInformation.ChiResident.Value = True)
    Set Cond2 = Range("L" & bot_row & ":AB" & bot_row).FormatConditions.Add(xlExpression, xlEqual, EmployeeInformation.Apprentice.Value = True)
    With Cond1
    .Font.Color = vbRed
    .Font.Bold = True
    .StopIfTrue = False
    End With
    With Cond2
    .Interior.Color = vbYellow
    .StopIfTrue = False
    End With
 
Upvote 0
That's great. Thanks for posting the code solution - saves me having to remind myself what the exact object/property name was... :-)
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,305
Members
452,633
Latest member
DougMo

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