Conditional Formatting using a macro

greatscottbattman

New Member
Joined
Mar 30, 2009
Messages
13
I'm trying record a macro to do the following:
=G2/E2>10% Highlight Green
=G2/E2<(10%) Highlight red
The column I'd like highlighted is G2

My objective is to only draw attention to a variance of 10% and -10%

Does anyone have any tips of trying to write this in VBA cuz I'm stuck as the record button does not work.

As always, much appreciated.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Code:
    [G2].Interior.ColorIndex = xlNone
    If [E2] <> 0 Then
        If [G2] / [E2] < 0.1 Then
            [G2].Interior.ColorIndex = 3     'Red
        ElseIf [G2] / [E2] >= 0.1 Then
            [G2].Interior.ColorIndex = 4     'Green
        End If
    End If
 
Upvote 0
I have about 80 sheets that can be updated any time by users. Then I have a macro that piles all 80 sheets on to one sheet. Each sheet has about 40 rows that a specific to people. But would like to have a summary report that would only show the +-10% highlighted. This can run at any time for the executive at a click of a button.
So the macro is building the one sheet with formatting and sorting and I'd like to add this conditional format if possible.

Hope that makes sense. I'd like the idea of a person clicking one button and all this happening on the summary sheet.

Everytime the macro runs, it deletes the summary sheet and creates a new one.
 
Upvote 0
Would it work for you that the macro adds the Conditional Formatting formulas instead of it looping through the cells and setting the background colors individuality?
 
Upvote 0
Code:
    With Range("G2:G3000")
        .FormatConditions.Delete
        .FormatConditions.Add Type:=xlExpression, Formula1:="=RC7/RC5>=10%"
        .FormatConditions(1).Interior.ColorIndex = 4    'Green
        .FormatConditions.Add Type:=xlExpression, Formula1:="=RC7/RC5<10%"
        .FormatConditions(2).Interior.ColorIndex = 3    'Red
    End With
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,741
Members
452,940
Latest member
rootytrip

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