Forum Discussion
Wannes_Tal
Oct 24, 2023Copper Contributor
Excel vba: crash on change conditional format
Hi, I have a conditional format on a range. Because the size of the range can change, I want also adapt dynamically the range on which the conditional format speaks . Since you cannot use named ra...
- Oct 25, 2023I have found a solution (for this possible bug?).
I now call a separate procedure, which contains only one line of code: range.ModifyAppliesToRange newrange. No matter how much times I call the procedure, it runs flawless.
For example:
sub example()
dim cfs as formatconditions
dim newFcRange as range
set cfs = myRange.formatconditions
set newFcRange = your new range here
For t = 1 to 8
call changeCF( cfs(t), newFcRange )
next t
do other stuff if needed...
end sub
sub changeCF( cf As FormatCondition, rg As Range )
cf.ModifyAppliesToRange rg
end sub
Wannes_Tal
Oct 25, 2023Copper Contributor
I have found a solution (for this possible bug?).
I now call a separate procedure, which contains only one line of code: range.ModifyAppliesToRange newrange. No matter how much times I call the procedure, it runs flawless.
For example:
sub example()
dim cfs as formatconditions
dim newFcRange as range
set cfs = myRange.formatconditions
set newFcRange = your new range here
For t = 1 to 8
call changeCF( cfs(t), newFcRange )
next t
do other stuff if needed...
end sub
sub changeCF( cf As FormatCondition, rg As Range )
cf.ModifyAppliesToRange rg
end sub
I now call a separate procedure, which contains only one line of code: range.ModifyAppliesToRange newrange. No matter how much times I call the procedure, it runs flawless.
For example:
sub example()
dim cfs as formatconditions
dim newFcRange as range
set cfs = myRange.formatconditions
set newFcRange = your new range here
For t = 1 to 8
call changeCF( cfs(t), newFcRange )
next t
do other stuff if needed...
end sub
sub changeCF( cf As FormatCondition, rg As Range )
cf.ModifyAppliesToRange rg
end sub