Excel-条件格式-插入行
在“应用于”中使用偏移或间接似乎不起作用。插入行后,是否有其他方法阻止条件格式中断 我有一个范围的条件格式,例如$O$19:$O$105。条件为“如果单元格值>10”,则其格式为红色 问题是-当我在excel中插入一行时,这个格式化范围会被分割,我会得到两个格式化规则。例如,如果我在第20行插入新行,范围分别为$O$19、$O$21:$O$105和$O$20的两条规则 通常情况下,对于上述情况,如果将规则划分为多个范围,则可能无关紧要。但对于“突出显示前10名”这样的情况,它会导致不期望的结果 我尝试了以下方法,但运气不太好:Excel-条件格式-插入行,excel,conditional-formatting,Excel,Conditional Formatting,在“应用于”中使用偏移或间接似乎不起作用。插入行后,是否有其他方法阻止条件格式中断 我有一个范围的条件格式,例如$O$19:$O$105。条件为“如果单元格值>10”,则其格式为红色 问题是-当我在excel中插入一行时,这个格式化范围会被分割,我会得到两个格式化规则。例如,如果我在第20行插入新行,范围分别为$O$19、$O$21:$O$105和$O$20的两条规则 通常情况下,对于上述情况,如果将规则划分为多个范围,则可能无关紧要。但对于“突出显示前10名”这样的情况,它会导致不期望的结果
这里有一个类似的线索,可以让你找到正确的方向:
它概述了R1C1样式格式的解决方法,该格式可能不受插入(未测试)以及我在评论中提到的VBA方法的影响。我意识到插入行不会导致条件格式规则的拆分。我还复制了一行并粘贴到插入的行中。如果我选择特殊的糊剂,只选择配方,效果很好
但是,我想知道是否有必要在条件格式的“应用于”字段中使用“间接”或“偏移量”。如果是这样,这将是一个问题。这是条件格式的一般问题。如果插入行或四处移动,Excel会假定您希望条件格式随单元格移动,并且您希望插入具有原始格式的单元格(或者根本不插入) 因此,它会尽力根据更改来分割格式化范围。不幸的是,“最好的”不是很好。幸运的是,你的格式规则会在你不注意的情况下被复制;在不幸的情况下,他们打破了部分或全部的应用范围 如果使用ListObjects(也称为“Excel表”),这尤其是一个问题。插入一些行,对其重新排序,拖动一些值,下次查看条件格式列表时,会有几十到几百条重复规则。(例如:) 根据我的经验,修复混乱的最快方法是删除所有规则并重新创建它们(或不重新创建) 一些旁注:
- “应用于”范围始终是绝对的。这是没有办法的
- 更糟糕的是,条件格式被视为易变公式,这意味着它们会在很多情况下重新计算(打开另一个文件、滚动等)。如果您没有注意到拆分,那么它们可能会在一段时间后显著降低整个应用程序的速度
- 如果您选择VBA,您可能希望使用工作表\u Calculate事件,至少在公式引用其他工作表的情况下(请注意名称!)
由于更改了公式,我现在可以在现有行之间插入新行,而不必像以前那样获取拆分规则。这是该网页的链接 我知道这是一个古老的线程,但这里有另一个解决方案,非常简单,效果非常好 只需根据需要插入新行或新列。然后选择并复制具有正确条件格式的行/列。将“过去特殊”插入刚创建的新行/列,并选择“所有合并条件格式”选项。您的条件格式规则现在应该自动更新
Happy Excel ing=)我在尝试创建报告时遇到了这个问题-一旦报告完成,它们就不需要更改,但在我创建报告的过程中,我不断添加新行,每一行都会破坏条件格式 这绝不是一个好的解决方案,但这是我在不使用VBA的情况下所能找到的最佳解决方案,即: a) 使条件格式规则一次应用于整列或多列 例如,不要在C2和C17上设置条件格式,而是增加一列,在第2行和第17行中写入“this one”,然后将整个C列的格式设置为“如果另一列显示‘this one’,则应用此格式” b) 将适用的更改为$C$1:$C$2 c) 进行更改并插入行和内容 d) 然后返回并将应用程序更改为$C:$C 这样,当您更改和添加内容时,条件格式不存在,但稍后您会将其全部放回 如果以后需要再添加几行,请首先将其从$C:$C更改为$C$1:$C$2,然后将
=$A2 <> $A1
=$A2<>OFFSET($A2; -1; 0)
Private Sub Workbook_Open()
'This will delete all conditional formatting and reapply the conditional formatting properly.
'After copying and pasting the conditional formatting get split into two or more conditional formattings. After a few
'weeks there are so many conditional formattings that Excel crashes and has to recover.
Dim ws As Worksheet, starting_ws As Worksheet
Set starting_ws = ActiveSheet 'remember which worksheet is active in the beginning
Application.ScreenUpdating = False
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "InvErr" Then
ws.Activate
Cells.FormatConditions.Delete
''Every Other Row Tan
Range("A4:M203").FormatConditions.Add Type:=xlExpression, Formula1:="=ISODD(ROW(A4))"
Range("A4:M203").FormatConditions(Range("A4:M203").FormatConditions.Count).SetFirstPriority
Range("A4:M203").FormatConditions(1).Interior.PatternColorIndex = xlAutomatic
Range("A4:M203").FormatConditions(1).Interior.ThemeColor = xlThemeColorDark2
Range("A4:M203").FormatConditions(1).Interior.TintAndShade = 0
Range("A4:M203").FormatConditions(1).StopIfTrue = False
''Highlight Duplicates Red
Columns("B").FormatConditions.AddUniqueValues
Columns("B").FormatConditions(Columns("B").FormatConditions.Count).SetFirstPriority
Columns("B").FormatConditions(1).DupeUnique = xlDuplicate
Columns("B").FormatConditions(1).Font.Color = -16383844
Columns("B").FormatConditions(1).Font.TintAndShade = 0
Columns("B").FormatConditions(1).Interior.PatternColorIndex = xlAutomatic
Columns("B").FormatConditions(1).Interior.Color = 13551615
Columns("B").FormatConditions(1).Interior.TintAndShade = 0
Columns("B").FormatConditions(1).StopIfTrue = False
End If
Next
starting_ws.Activate 'activate the worksheet that was originally active
Application.ScreenUpdating = True
End Sub
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