Applying conditional formatting

Diving_Dan

Board Regular
Joined
Oct 20, 2019
Messages
161
Morning all,

I'm having a few issues trying to write some code for conditional formatting. I'm going to be adding a loop shortly but want to get this working first.

So I get an error "Expected: end of statement" with the following code for the 2nd line of code.

I know the issue is because of the quotes around "role" but I need the quotes because of the formula. How do I make this work?

VBA Code:
Sub add_con_formatting()
    
    Range("h11").Select
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=G11="role""
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 65535
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    Range("C6").Select
    
End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
If I remember correctly, the macro recorder doesn't pick up conditional formatting, but you could record yourself typing the formula into a cell on the worksheet in order to get the correct syntax for any similar problems.

edit:- the macro recorder will give you the cell references in R1C1 notation so you would need to change those, but it will show you the correct duplication of the double quotes where needed.
 
Upvote 0

Forum statistics

Threads
1,215,052
Messages
6,122,878
Members
449,097
Latest member
dbomb1414

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