Help With Conditional Formatting in a Macro

Lazarus416

Board Regular
Joined
Feb 20, 2013
Messages
103
Apologies if this is covered somewhere, but I am trying to play catch up after a 6 month deployment and I have not had time to search...

I need to know how to apply conditional formatting in a macro using the following formulas to a range of cells please...(recording does not seem to work).

Range: =$D$4:$E$185,$D$187:$E$203
=$D4="Not on Psnl Rpt"
(Fill with Red, Accent 2, lighter 40%)

Range: =$D$4:$D$203
(Fill with Orange)

I have some others, but I think with these 2 examples I can puzzle out the rest. (Or just copy/paste and modify if I need to.) Thanks in advance for any assistance.

Laz
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
try in a copy

Code:
Sub fillRange()

Dim myRange As Range, c As Range
Set myRange = Range("D4:D185", "D187:D203")
For Each c In myRange
    If c.Value = "Not on Psnl Rpt" Then
        With c.Resize(, 2).Interior
            .ThemeColor = xlThemeColorAccent2
            .TintAndShade = 0.399975585192419
        End With
    End If
Next c
End Sub
 
Upvote 0
Hmmm. Awesome. It works, however, the one thing I see is that the conditional format rule does not show up in the "Manage Rules" drop down menu, so I can't go back and adjust the applicable cells or formulas if they change at all. Any idea how to make it show up in the conditional format rules for the worksheet?

Laz
 
Upvote 0
So I found some additional info on this and I have a partial solution, but I am missing something somewhere...

Code:
With Range("D2:D200").FormatConditions.Add( _
        Type:=xlExpression, _
        Formula1:="D2" <> "Not on Psnl Rpt")
        
        .Interior.Color = RGB(198, 239, 206)
        .Font.Color = RGB(0, 97, 0)

This code processes the argument correctly, but it highlights everything in the range instead of just the cells where the formula is TRUE. How do I make the conditional formatting only apply to the appropriate cells? Anyone know?

(Btw, anyone know where I can go to see what the RGB is for the different colors?)
 
Upvote 0
So, as it turns out, the macro recorder WILL record conditional formatting, but ONLY if you select the cells you want to apply it to first and then set the conditional formatting. It won't record it if you start from the CF menu first.
 
Upvote 0

Forum statistics

Threads
1,222,141
Messages
6,164,165
Members
451,880
Latest member
2da

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