Excel 多重重叠条件格式

Excel 多重重叠条件格式,excel,vba,conditional-formatting,Excel,Vba,Conditional Formatting,我写下了下面的代码: Sub formatCondMesi() Worksheets(1).Unprotect Password:="ponzio" Dim i As Integer 'For i = 2 To 13 Worksheets(1).Select Worksheets(1).Cells.FormatConditions.Delete '1) With Worksheets(1).Application.Union(Range("C7:O149"), Range("C155:O

我写下了下面的代码:

    Sub formatCondMesi()
Worksheets(1).Unprotect Password:="ponzio"
Dim i As Integer
'For i = 2 To 13
Worksheets(1).Select
Worksheets(1).Cells.FormatConditions.Delete
'1)
With Worksheets(1).Application.Union(Range("C7:O149"), Range("C155:O297"), Range("C303:O445"), Range("C451:O593"))
.FormatConditions.Add Type:=xlExpression, Formula1:="=$H7<0"
.FormatConditions(1).Font.ColorIndex = 3
End With
'2)
With Worksheets(1).Application.Union(Range("J150"), Range("L150"), Range("N150:O150"))
.FormatConditions.Add Type:=xlExpression, Formula1:="=$E150="""""
.FormatConditions(1).Font.ColorIndex = 2
End With

'3)
i = 1
If i = 1 Then
    A = Worksheets(1).Range("F4").Value
    B = Worksheets(1).Range("F5").Value
End If
With Worksheets(1).Application.Union(Range("E7:E149"), Range("E155:E297"), Range("E303:E445"), Range("E451:E593"))
.FormatConditions.Add Type:=xlExpression, Formula1:="=OR($E7<" & A & ";$E7>" & B & ")"  '43101 43131
'.FormatConditions(1).SetFirstPriority = True
.FormatConditions(1).Font.ColorIndex = 3
.FormatConditions(1).Font.Bold = True
.FormatConditions(1).Font.Strikethrough = True
End With

'4)
With Worksheets(1).Application.Union(Range("O7:O149"), Range("O447:O593"), Range("O299:O445"), Range("O151:O297"))
.FormatConditions.Add Type:=xlExpression, Formula1:="=$O7=0"
.FormatConditions(1).Font.ColorIndex = 3
End With

'5)
With Worksheets(1).Application.Union(Range("L7:L149"), Range("L151:L297"), Range("L299:L445"), Range("L447:L593"))
.FormatConditions.Add Type:=xlExpression, Formula1:="=ISNA($L7)"
.FormatConditions(1).Font.ColorIndex = 2
End With

End Sub
子格式condmesi()
工作表(1)。取消保护密码:=“ponzio”
作为整数的Dim i
'对于i=2到13
工作表(1)。选择
工作表(1).Cells.FormatConditions.Delete
'1)
随附工作表(1).Application.Union(范围(“C7:O149”)、范围(“C155:O297”)、范围(“C303:O445”)、范围(“C451:O593”))
.FormatConditions.Add类型:=xlExpression,公式1:=“=$H7对于问题1),可能您必须添加

.FormatConditions(1).StopIfTrue = True
否则,将检查并应用所有条件格式规则

对于问题2):您是否有机会使用Excel 2003?在这里,规则的最大数量限制为3个,所以这可能是您的问题。否则我不知道,我做了一个快速测试,可以添加3个以上的规则而没有问题。

对于问题1),您可能必须添加

.FormatConditions(1).StopIfTrue = True
否则,将检查并应用所有条件格式规则


对于问题2):您是否有机会使用Excel 2003?在这里,规则的最大数量限制为3个,因此这可能是您的问题。否则我不知道,我做了一个快速测试,可以添加3个以上的规则,没有问题。

为什么您将
I
设置为1,然后立即检查
I=1
?这只是为了调试目的吗poses?抱歉,现在我编辑并正确更正。为什么您会将
i
设置为1,然后立即检查
i=1
?这只是为了调试目的吗?抱歉,现在我编辑并正确更正了。我,请再次阅读代码,因为我错误地粘贴了文本内容。现在我已经修改了。感谢大家的帮助,我的excel是2010 professional pack。非常感谢,我将尝试您的提示并更新结果。谢谢Hello,我尝试了您上面的提示(stopiftrue=true),但没有任何更改。您的意思是stopiftrue=false吗?我应该禁用它吗?您好,请重新阅读代码,因为我错误地粘贴了文本内容。现在我已经修改了。感谢所有人的帮助我的excel is 2010 professional pack。非常感谢,我将尝试您的提示并更新结果。谢谢Hello,我尝试了您上面的提示(stopiftrue=true),但没有任何变化。你的意思是stopiftrue=false吗?我应该禁用它吗?