Forum Discussion

Wannes_Tal's avatar
Wannes_Tal
Copper Contributor
Oct 24, 2023
Solved

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...
  • Wannes_Tal's avatar
    Oct 25, 2023
    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

Resources