VBA Conditional Formatting - This Has Got To Be Easy

monoskim

New Member
Joined
Nov 1, 2010
Messages
7
So i want to apply conditional formatting to cell A1 based on whether lets say D1 says... (D1 is linked to A1, supplying "Error" or "No Error" based on some criteria I've established) If "No Error" then I dont want to do anyting, but if D1 says "Error" I want A1 to turn red. I need this in vba code becuase I want to apply that same conditional format to a dynamic range as i get data in A2, A3, etc. I know how to figure that piece out, I just cant seem to get the cond format to work in vba.

Thanks much,
Mike
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Try ~
Where the code says ~ Columns("A:A").Select
Put in the range you wish colored red. i.e. if your range was A5:A12 you would put ~

Range ("A5:A12").Select
If you had a named range, say your range was named colorme you would have ~
Range ("colorme").Select
your named range may be a dynamic range.
Be aware though that once the Conditional format is set, it will stay till you clear the conditional formatting rules either by the macro or manually.

Code:
Sub Macro6()
    Columns("A:A").Select
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=$D1=""error"""
    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

Cheers
 
Upvote 0

Forum statistics

Threads
1,224,607
Messages
6,179,871
Members
452,949
Latest member
Dupuhini

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