Can i get existing conditional formatting into a macro?

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi everyone,
I have used the macro recorder in the past to get conditional formatting into vba, but I can only get it to work when i create anew rule,

is there a way to extract all conditioning formatting rules into vba so i can run them and edit them etc.

any ideas would be helpful

Thanks

Tony
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Probably simpler to just get a macro to delete all the rules & create the new ones.
 
Upvote 0
You can probe Conditional Formatting with code like this. But some of the properties values can be a little obscure.
What do you mean by running a conditional format?
VBA Code:
Sub test()
    Dim oneCell, oneCondition As FormatCondition
    For Each oneCell In ActiveSheet.UsedRange
        With oneCell
            If .FormatConditions.Count > 0 Then
                For Each oneCondition In .FormatConditions
                    MsgBox oneCondition.Formula1 & " applies to " & oneCondition.AppliesTo.Address
                Next oneCondition
            End If
        End With
    Next
End Sub
 
Upvote 0
HI Thanks for your help,
what I'm trying to do is get all my conditional formatting rules into a macro,
if i was to create them now, I could record the rule being created with the macro recorder, but as they are already in there i cant seam to get to them, if i try editing the rule with the macro recorder on nothing get recorded.

basically my conditional formatting keeps getting massed up when rows, ranges cells are copy pasted, inserted etc, so what ive done in the past if set up my macro to reset all conditions as i want them and just run it at set times (after a copy and paste for example, this idea works great but i have about 50 rules so getting them into a macro means retyping them all with the macro recorder on. before i do this and spend a day or two on it i was wondering if there is a way to get the rulles as they are all in the sheet exactly as i want them now, and put them into a macro with vba? any help would be appreciated.

Thanks
 
Upvote 0
There's no way I know of, that will create a macro with your CF formula, ranges etc.
You could use the code from mikerickson to find out what the formats are, but you would still need to create another macro to apply them.
 
Upvote 0
If that is the problem, what I join Fluff in suggesting that you record yourself
1) clearing all CF
2) setting up the CF the way that you want it.
 
Upvote 0
Hi Guys,
Oh well, looks like it a weekend of slogging away then lol :(
thanks for your help
Tony
 
Upvote 0
Glad we could help (even if it wasn't what you wanted the hear) & thanks for the feedback.
 
Upvote 0
I know this is an old post, but here is how I accomplish this.

Start recording macro → Conditional Formatting Manage Rules → Create a bogus rule with a formatting → Apply → Delete Rule → Click OK → Stop recording Macro. All rules are now listed in macro you have just recorded.
 
Upvote 0
I know this is an old post, but here is how I accomplish this.

Start recording macro → Conditional Formatting Manage Rules → Create a bogus rule with a formatting → Apply → Delete Rule → Click OK → Stop recording Macro. All rules are now listed in macro you have just recorded.
Brilliant thank you :)
 
Upvote 0

Forum statistics

Threads
1,214,991
Messages
6,122,628
Members
449,095
Latest member
bsb1122

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