How to copy the new Excel 2007 conditional formats
I know, I'm late to the party and not going to be much fun while here.
But start by declaring your condition variable as type FormatCondition:
Dim condition As FormatCondition
Then in your loop you can examine the various properties of a
FormatCondition such as
..Application
..AppliesTo
..Borders
..Creator
..DateOperator
..Font
..Formula1
..Formula2
..NumberFormat
..Interior
..Operator
etc.
You will have to either Add or Modify the conditional formatting in your
target cell and set things up the way you want. See FormatConditions in
Help. There is also a new ConditionValue object that deals with data bar
conditional formatting.
"Josh Sale" wrote:
I have a cell that has been formatted using XL2007's fancy new conditional
formats (you know data bars, color scales, icon sets, etc) and I want to
copy those conditional formats to another cell in my code. I know this can
be done using Copy and PasteSpecial but this is to blunt an instrument
(i.e., Copy and PasteSpecial will transfer more properties from the source
to the target than I want). All I want is to copy the conditional formats.
It looks like the conditional format lives in the FormatConditions
collection of the range object but I'm not sure how to copy them.
For example, Target.FormatConditions = Source.FormatConditions doesn't work.
I can loop through them:
For Each condition in Source.FormatConditions
' what do I do here? Maybe ...
Target.FormatConditions.Add condition.????
' or maybe?
Target.FormatConditions.AddIconSetCondition condition.???
Next condition
Yikes.
TIA,
josh
|