4
votes

Can I copy conditional formatting from one cell to another using VBA?

I'm imagining something like:

Sheets("A").Range("A1:A10").ConditionalFormatting = Sheets("B").Range("B1").ConditionalFormatting
1
there is not a specfic paste option for conditional formats, however there is a merge , so as long as the destination cells dont have an unique conditional formatting to the source cells then you can use copy and paste special with type "xlPasteAllMergingConditionalFormats"Steven Martin
I was going to suggest you use the FormatConditions.ModifiesApplyToRange method. That will only work if the Conditional Formatting is on the same sheet though.Doug Glancy

1 Answers

3
votes

use this:

Sub test()
     Sheets("B").[B1].Copy: Sheets("A").[A1:A10].PasteSpecial xlPasteFormats
End Sub