Excel - Conditional Formatting - insert row

前端 未结 16 1604
轮回少年
轮回少年 2021-01-01 11:37

Using Offset or Indirect in \'Applies To\' does not seem to work. Is there any other way to stop conditional formatting from breaking after inserting row/s

16条回答
  •  遥遥无期
    2021-01-01 12:25

    This worked well enough for me...

    Sub ConditionalFormattingRefresh()
    '
    ' ConditionalFormattingRefresh Macro
    '
    
    'Generales
    Dim sh As Worksheet
    Dim tbl As ListObject
    Dim selectedCell As Range
    Set sh = ActiveSheet
    Set tbl = Range("Plan").ListObject
    Set selectedCell = ActiveCell
    
    'Rango a copiar
    Dim copyRow As Range
    Set copyRow = tbl.ListRows(1).Range
    
    'Rango a restaurar
    Dim startCell As Range
    Dim finalCell As Range
    Dim refreshRange As Range
    Set startCell = tbl.DataBodyRange.Cells(2, 1)
    Set finalCell = tbl.DataBodyRange.Cells(tbl.ListRows.Count, tbl.ListColumns.Count)
    Set refreshRange = Range(startCell.Address, finalCell)
    
    'Ocultar procesamiento
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    
    'Borrar formato corrupto
    refreshRange.FormatConditions.Delete
    
    'Copiar
    copyRow.Copy
    'Pegar formato
    tbl.DataBodyRange.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
    
    'Retornar a la normalidad
    selectedCell.Select
        Application.ScreenUpdating = True
    Application.EnableEvents = True
    
    End Sub
    

提交回复
热议问题