I have a conditional formatting rule defined as macro, which deletes the old rules and replaces them with updates ones:
Sub setCondFormat()
Set Table = ActiveSheet.ListObjects("Rules")
Table.Range.FormatConditions.Delete
Set Attribute = Table.ListColumns("Attribute")
With Attribute.DataBodyRange.FormatConditions _
.Add(xlExpression, xlEqual, "=ISEMPTY(A2)")
With .Interior
.ColorIndex = 0
End With
End With
End Sub
The conditional formatting in Excel needs to be updated. Otherwise the cell ranges in the rules get fragmented.
Let's say you have two rules:
- Make
$A$1:$A$30
red - Make
$B$1:$B$30
blue Now selectA10:B10
and copy/paste that toA20:B20
.
What Excel will do is to delete the conditional formatting.
For A20:B20
from the rules that applied to those cells and add new
rules that have the formatting for A20:B20
. You end up with four
rules:
- Make
=$A$20
red - Make
=$B$20
blue - Make
=$A$1:$A$19,$A$21:$A$30
red - Make
=$B$1:$B$19,$B$21:$B$30
blue
This happens, when the table structure gets changed through cut/paste/delete/insert events.
How to trigger the above VBA macro on cut/paste/delete/insert events?