我使用了以下记录器宏:
Application.ScreenUpdating = False
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _
Formula1:="=0", Formula2:="=19.5"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Bold = False
.Italic = True
.ColorIndex = 4
End With
Selection.FormatConditions(1).StopIfTrue = True
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _
Formula1:="=19.6", Formula2:="=34.4"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Bold = False
.Italic = True
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.499984740745262
End With
Selection.FormatConditions(1).StopIfTrue = False
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.FormatConditions(1).StopIfTrue = False
然后我使用宏来删除所有条件并仅保留格式。但是,无论我做什么,Isblank,添加另一个条件格式条件仅在非空白上运行,在条件格式宏之后,格式设置为绿色(将任何 0-19.5 变为绿色,但单元格中没有任何内容)。
有没有办法给这个宏添加跳线?如果它是空白的,我希望它移动到下一个单元格。我没有设置范围,所以这就是为什么它全部取决于选择。
最佳答案
您可以循环遍历所选内容中的每个单元格,并且仅在单元格不为空时应用格式。
Option Explicit
Sub test()
Dim cel As Range
Application.ScreenUpdating = False
On Error Resume Next
For Each cel In Selection
If cel <> "" Then
cel.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _
Formula1:="=0", Formula2:="=19.5"
cel.FormatConditions(cel.FormatConditions.Count).SetFirstPriority
With cel.FormatConditions(1).Font
.Bold = False
.Italic = True
.ColorIndex = 4
End With
cel.FormatConditions(1).StopIfTrue = True
cel.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _
Formula1:="=19.6", Formula2:="=34.4"
cel.FormatConditions(cel.FormatConditions.Count).SetFirstPriority
With cel.FormatConditions(1).Font
.Bold = False
.Italic = True
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.499984740745262
End With
cel.FormatConditions(1).StopIfTrue = False
With cel
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
cel.FormatConditions(1).StopIfTrue = False
End If
Next cel
Application.ScreenUpdating = True
End Sub
关于excel - 在 Excel 中使用条件格式宏跳过空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17371466/