M
mikelee101
Hello,
I have a rather large range of cells that have 3 conditional formats. I'd
like to change the order that the formats are applied. However, most of the
cells also have other "unconditional" formats, so simply making the changes
in one cell then copying/pasting formats would mean having to go back through
and manually change those. So, I'm looking for a way to change the order of
the formats in VBA. However, I'm getting stuck at, what should be, the very
end. I've been able to move the formatconditions object to a variable (as
near as I can tell, anyway), but then can't move the object from the variable
back to the formatconditions object. I've tried the add method and the
modify method, but both give me a runtime error. Below is snip of the code:
----------
Dim Wkbk As Workbook, Nme As String, rng As Range, Cl As Range
Dim Valhldr(1 To 3) As Object
Set Wkbk = ActiveWorkbook
Nme = "testrange"
Set rng = Wkbk.Names(Nme).RefersToRange
For Each Cl In rng
For i = 1 To 3
Set Valhldr(i) = Cl.FormatConditions(i)
Next i
For i = 1 To 3
Cl.FormatConditions(1).Delete
Next i
Cl.FormatConditions(1).Add = Valhldr(3)
Cl.FormatConditions(2).Add = Valhldr(1)
Cl.FormatConditions(3).Add = Valhldr(2)
Next Cl
--------------------
So, if anyone has any suggestions on how I can move the formats from the
variable back to the formatconditions, or has another suggestion on how I can
do this, I'd really appreciate it. The conditions themselves are rather
complex formulas. Hardcoding them is an option, but figured I'd see if this
could work.
Thanks to all.
I have a rather large range of cells that have 3 conditional formats. I'd
like to change the order that the formats are applied. However, most of the
cells also have other "unconditional" formats, so simply making the changes
in one cell then copying/pasting formats would mean having to go back through
and manually change those. So, I'm looking for a way to change the order of
the formats in VBA. However, I'm getting stuck at, what should be, the very
end. I've been able to move the formatconditions object to a variable (as
near as I can tell, anyway), but then can't move the object from the variable
back to the formatconditions object. I've tried the add method and the
modify method, but both give me a runtime error. Below is snip of the code:
----------
Dim Wkbk As Workbook, Nme As String, rng As Range, Cl As Range
Dim Valhldr(1 To 3) As Object
Set Wkbk = ActiveWorkbook
Nme = "testrange"
Set rng = Wkbk.Names(Nme).RefersToRange
For Each Cl In rng
For i = 1 To 3
Set Valhldr(i) = Cl.FormatConditions(i)
Next i
For i = 1 To 3
Cl.FormatConditions(1).Delete
Next i
Cl.FormatConditions(1).Add = Valhldr(3)
Cl.FormatConditions(2).Add = Valhldr(1)
Cl.FormatConditions(3).Add = Valhldr(2)
Next Cl
--------------------
So, if anyone has any suggestions on how I can move the formats from the
variable back to the formatconditions, or has another suggestion on how I can
do this, I'd really appreciate it. The conditions themselves are rather
complex formulas. Hardcoding them is an option, but figured I'd see if this
could work.
Thanks to all.