Excel - Conditional Formatting - insert row

前端 未结 16 1492
轮回少年
轮回少年 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:23

    I know this is an old thread but here's another solution that's super simple and works great.

    Simply insert a new row or column as desired. Then select and copy a row/column that has the correct conditional formatting. Past Special into the new row/column that you just created and select the option for "All merging conditional formats". Your conditional formatting rules should now be automatically updated.

    Happy Excel-ing =)

    0 讨论(0)
  • 2021-01-01 12:23

    I realized that insert row is not causing the splitting of the conditional formatting rules. I also copy a row and paste in the inserted row which is doing this. If I opt for special paste and choose formulas only, its working fine.

    However, I wonder if there would ever be a need to use 'INDIRECT' or 'OFFSET' in 'Applies to' field of Conditional Formatting. If so, it's going to be a problem.

    0 讨论(0)
  • 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
    
    0 讨论(0)
  • 2021-01-01 12:25

    I have found a simple process that seems to work consistently for inserting new rows or columns AND preserves the continuity of the conditional formatting rules (in Office 2010 at least), as follows:

    1. Do a simple "Insert" of your desired number of new rows or columns above, below or left or right of a row or column containing the conditional formatting to be preserved.

    NOTE a) Your conditional formatting is automatically applied to the inserted rows or columns without you having to do anything further. The formatting should have been inherited from the neighboring row or column. b) Any borders formatting should also have been copied to the newly inserted cells.

    1. Select a row, column or range (by clicking it) that is adjacent to the newly inserted ones, and which contains the conditional formatting (and formulas and data if applicable) to be copied.

    2. Hover your mouse over the lower left or lower right corner of the selected range until you see a plus "+" sign appear (don't confuse it with the row re-size gadget as they look similar).

    3. Left click and hold on "+", and drag across the desired rows, columns or range to be formatted, then release.

    NOTE: I create Conditional Formatting rules referencing only one cell: Example) in the field titled "Format values where this formula is true:", create a rule such as ... =AND($B8="",$C8="",$D8="",$K8<>""), where this rule Applies to say the range ... =$B$8:$D$121,$J$8:$M$121.

    0 讨论(0)
  • 2021-01-01 12:26

    I got it to work on Excel Mac 2011 by the following steps

    • inserting the new row
    • copying the one above it (with the conditional formatting already applied)
    • highlighting the new row and PASTE SPECIAL -> MERGE CONDITIONAL FORMATTING.

    The CF rules stayed unsplit and updated to include an additional row.

    0 讨论(0)
  • 2021-01-01 12:27

    Here's a similar thread that may get you ont he right track:

    How to use the Worksheet_Change event for Conditional Formatting?

    It outlines a workaround to R1C1 style formatting which may not be affected by the inserts (untested) along with the VBA approach I mentioned in the comments.

    0 讨论(0)
提交回复
热议问题