Meaningful way to easily (not mysteriously) change colors in my macro?

Gingertrees

Well-known Member
Joined
Sep 21, 2009
Messages
697
In my macro, I utilize conditional formatting to create alternating rows of color. The powers that be have tired of the sage green I've been using. How do I easily change the color in the following piece of code? Say I want to change it to pink, and then later on I change my mind and want to set it to light blue.

I know I could just take a stab at changing numbers - but is there a better way? Maybe set these to HEX colors?
Code:
Cells.Select    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=MOD(ROW(),2)=1"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent6
        .TintAndShade = 0.599963377788629
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Maybe

Code:
    With Cells.FormatConditions
        .Delete
        .Add Type:=xlExpression, Formula1:="=MOD(ROW(),2)"
        .Item(1).SetFirstPriority
        With .FormatConditions(1).Interior
            .Color = RGB(255, 225, 225)

That's an awful lot of formatting to add, though.
 
Upvote 0
You're adding conditional formatting to every cell on the sheet.

The code had a mistake:

Code:
    With Cells.FormatConditions
        .Delete
        .Add Type:=xlExpression, Formula1:="=MOD(ROW(),2)=1"
        With .Item(1)
            .SetFirstPriority
            .Interior.Color = RGB(255, 225, 225)
        End With
    End With
 
Upvote 0
Oh. That might explain why it takes so long to run.
This is pretty much just what the macro recorder transcribed. How would I tell it "for used range, apply this conditional formatting"?
 
Upvote 0
Code:
  Cells.FormatConditions.Delete
  
  With ActiveSheet.UsedRange.FormatConditions
        .Add Type:=xlExpression, Formula1:="=MOD(ROW(),2)=1"
        With .Item(1)
            .SetFirstPriority
            .Interior.Color = RGB(255, 225, 225)
        End With
    End With
 
Upvote 0
You're welcome, good luck.

You could also use the color selection tool for cell interior and font color formatting.
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,094
Latest member
teemeren

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