gpt4 book ai didi

excel - 让条件格式宏在 Excel 中跳过空白

转载 作者:行者123 更新时间:2023-12-04 20:17:53 31 4
gpt4 key购买 nike

我使用了以下记录器宏:

 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/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com