我在循环vba时遇到问题

我在循环vba时遇到问题,vba,excel,Vba,Excel,我有一个将条件格式应用于工作表的宏。我想将此格式应用于工作簿中的每个工作表。我将工作表调暗,并将每个工作表和下一个工作表都包含在vba中,但不是每个工作表都循环 Sub Con() Dim wkst As Worksheet For Each wkst In ThisWorkbook.Sheets Range("B4:D4,G4,K4:M4").Select With Selection.Interior .Pattern = xlSolid .PatternColorI

我有一个将条件格式应用于工作表的宏。我想将此格式应用于工作簿中的每个工作表。我将工作表调暗,并将每个工作表和下一个工作表都包含在vba中,但不是每个工作表都循环

Sub Con()
Dim wkst As Worksheet

For Each wkst In ThisWorkbook.Sheets

 Range("B4:D4,G4,K4:M4").Select

With Selection.Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent1
    .TintAndShade = -0.249977111117893
    .PatternTintAndShade = 0
End With
    Range("F1:J1").Select
With Selection.Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .Color = 49407
    .TintAndShade = 0
    .PatternTintAndShade = 0
End With

Range("E8").Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
    Formula1:="E8>E9"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 5287936
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
    Formula1:="E8<E9"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 255
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
    "=OR(E8="""",E8=0)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent1
    .TintAndShade = 0.799981688894314
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.Copy
Range("E8:Q8").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False


Range("E11").Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
    Formula1:="=E11>E12"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 5287936
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
    Formula1:="=E11<E12"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 255
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
    "=OR(E11="""",E11=0)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlNone
    .TintAndShade = 0
    .PatternTintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.Copy
Range("E11:Q11").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False


'--------------------------------------------------------------------------------------------------------'
Range("E17").Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
    Formula1:="=E17>E18"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 5287936
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
    Formula1:="=E17<E18"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 255
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
    "=OR(E17="""",E17=0)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent3
    .TintAndShade = 0.799981688894314
    .PatternTintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.Copy
Range("E17:Q17").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False


'''----------------------------------------------------------------------------------------------------------------------------------'''''

Range("E20").Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
    Formula1:="=E20>E21"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 5287936
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
    Formula1:="=E20<E21"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 255
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
    "=OR(E20="""",E20=0)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent1
    .TintAndShade = 0.799981688894314
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.Copy
Range("E20:Q20").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False

'''----------------------------------------------------------------------------------------------------------------------------------'''''
'''----------------------------------------------------------------------------------------------------------------------------------'''''
'''----------------------------------------------------------------------------------------------------------------------------------'''''

Range("E23").Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
    Formula1:="=E23>E24"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 5287936
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
    Formula1:="=E23<E24"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 255
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
    "=OR(E23="""",E23=0)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent3
    .TintAndShade = 0.799981688894314
    .PatternTintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.Copy
Range("E23:Q23").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False

Range("E26").Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
    Formula1:="=E26>E27"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 5287936
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
    Formula1:="=E26<E27"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 255
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
    "=OR(E26="""",E26=0)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent1
    .TintAndShade = 0.799981688894314
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.Copy
Range("E26:Q26").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

Range("E30").Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
    Formula1:="=E30>E31"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 5287936
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
    Formula1:="=E30<E31"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 255
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
    "=OR(E30="""",E30=0)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent3
    .TintAndShade = 0.799981688894314
    .PatternTintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.Copy
Range("E30:Q30").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False

Range("E42").Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
    Formula1:="=E42<E43"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 5287936
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
    Formula1:="=E42>E43"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 255
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
    "=OR(E42="""",E42=0)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent3
    .TintAndShade = 0.799981688894314
    .PatternTintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.Copy
Range("E42:Q42").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False

Range("E33").Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
    Formula1:="=E33>E34"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 5287936
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
    Formula1:="=E33<E34"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 255
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
    "=OR(E33="""",E33=0)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent1
    .TintAndShade = 0.799981688894314
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.Copy
Range("E33:Q33").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

Range("E39").Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
    Formula1:="=E39>E40"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 5287936
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
    Formula1:="=E39<E40"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 255
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
    "=OR(E39="""",E39=0)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent1
    .TintAndShade = 0.799981688894314
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.Copy
Range("E39:Q39").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

Next

Application.ScreenUpdating = True

End Sub
subcon()
将wkst设置为工作表
对于此工作簿中的每个wkst。工作表
范围(“B4:D4、G4、K4:M4”)。选择
有选择。内饰
.Pattern=xlSolid
.PatternColorIndex=xlAutomatic
.ThemeColor=xlThemeColorAccent1
.TintAndShade=-0.249977111117893
.PatternTintAndShade=0
以
范围(“F1:J1”)。选择
有选择。内饰
.Pattern=xlSolid
.PatternColorIndex=xlAutomatic
.Color=49407
.TintAndShade=0
.PatternTintAndShade=0
以
范围(“E8”)。选择
Selection.FormatConditions.Add类型:=xlCellValue,运算符:=xlGreater_
公式1:=“E8>E9”
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
带选择。格式条件(1)。内部
.PatternColorIndex=xlAutomatic
.颜色=5287936
.TintAndShade=0
以
Selection.FormatConditions(1).StopIfTrue=False
Selection.FormatConditions.Add类型:=xlCellValue,运算符:=xlLess_
公式1:=“E8E12”
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
带选择。格式条件(1)。内部
.PatternColorIndex=xlAutomatic
.颜色=5287936
.TintAndShade=0
以
Selection.FormatConditions(1).StopIfTrue=False
Selection.FormatConditions.Add类型:=xlCellValue,运算符:=xlLess_
公式1:=“=E11E18”
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
带选择。格式条件(1)。内部
.PatternColorIndex=xlAutomatic
.颜色=5287936
.TintAndShade=0
以
Selection.FormatConditions(1).StopIfTrue=False
Selection.FormatConditions.Add类型:=xlCellValue,运算符:=xlLess_
公式1:=“=E17E21”
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
带选择。格式条件(1)。内部
.PatternColorIndex=xlAutomatic
.颜色=5287936
.TintAndShade=0
以
Selection.FormatConditions(1).StopIfTrue=False
Selection.FormatConditions.Add类型:=xlCellValue,运算符:=xlLess_
公式1:=“=E20E24”
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
带选择。格式条件(1)。内部
.PatternColorIndex=xlAutomatic
.颜色=5287936
.TintAndShade=0
以
Selection.FormatConditions(1).StopIfTrue=False
Selection.FormatConditions.Add类型:=xlCellValue,运算符:=xlLess_
公式1:=“=E23E27”
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
带选择。格式条件(1)。内部
.PatternColorIndex=xlAutomatic
.颜色=5287936
.TintAndShade=0
以
Selection.FormatConditions(1).StopIfTrue=False
Selection.FormatConditions.Add类型:=xlCellValue,运算符:=xlLess_
公式1:=“=E26E31”
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
带选择。格式条件(1)。内部
.PatternColorIndex=xlAutomatic
.颜色=5287936
.TintAndShade=0
以
Selection.FormatConditions(1).StopIfTrue=False
Selection.FormatConditions.Add类型:=xlCellValue,运算符:=xlLess_
公式1:=“=E30E34”
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
带选择。格式条件(1)。内部
.PatternColorIndex=xlAutomatic
.颜色=5287936
.TintAndShade=0
以
Selection.FormatConditions(1).StopIfTrue=False
Selection.FormatConditions.Add类型:=xlCellValue,运算符:=xlLess_
公式1:=“=E33E40”
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
带选择。格式条件(1)。内部
.PatternColorIndex=xlAutomatic
.颜色=5287936
.TintAndShade=0
以
Selection.FormatConditions(1).StopIfTrue=False
Selection.FormatConditions.Add类型:=xlCellValue,运算符:=xlLess_

公式1:=“=E39在For Each语句后添加此行,使其在每张工作表中迭代:

wkst.Activate

免责声明:Scott Craner和Comintern是正确的。使用Activate、.Select和Selection会导致更慢、更容易出错的代码。按照他们的建议,最终会得到最好的结果。

这里是我问题答案的更新,所以我找到了答案。这与.Activate或.Select无关,实际上我不得不选择是什么是活动工作表

Sub Con()
Dim sht As Worksheet, csheet As Worksheet
Call removecond
Application.ScreenUpdating = False
Set csheet = ActiveSheet
For Each sht In ActiveWorkbook.Worksheets
If sht.Visible Then
sht.Activate
Range("E8").Select
 Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=E8>E9"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 5287936
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=E8<E9"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 255
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
    "=OR(E8="""",E8=0)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent1
    .TintAndShade = 0.799981688894314
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.Copy
Range("E8:Q8").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False

Range("E11").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=E11>E12"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 5287936
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=E11<E12"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 255
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
    "=OR(E11="""",E11=0)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlNone
    .TintAndShade = 0
    .PatternTintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.Copy
Range("E11:Q11").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False

Range("E17").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=E17>E18"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 5287936
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=E17<E18"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 255
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
    "=OR(E17="""",E17=0)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent3
    .TintAndShade = 0.799981688894314
    .PatternTintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.Copy
Range("E17:Q17").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False

Range("E20").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=E20>E21"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 5287936
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=E20<E21"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 255
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
    "=OR(E20="""",E20=0)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent1
    .TintAndShade = 0.799981688894314
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.Copy
Range("E20:Q20").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False

Range("E23").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=E23>E24"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 5287936
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=E23<E24"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 255
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
    "=OR(E23="""",E23=0)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent3
    .TintAndShade = 0.799981688894314
    .PatternTintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.Copy
Range("E23:Q23").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False

Range("E26").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=E26>E27"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 5287936
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=E26<E27"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 255
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
    "=OR(E26="""",E26=0)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent1
    .TintAndShade = 0.799981688894314
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.Copy
Range("E26:Q26").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

Range("E30").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=E30>E31"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 5287936
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=E30<E31"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 255
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
    "=OR(E30="""",E30=0)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent3
    .TintAndShade = 0.799981688894314
    .PatternTintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.Copy
Range("E30:Q30").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False

Range("E42").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=E42<E43"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 5287936
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=E42>E43"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 255
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
    "=OR(E42="""",E42=0)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent3
    .TintAndShade = 0.799981688894314
    .PatternTintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.Copy
Range("E42:Q42").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False

Range("E33").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=E33>E34"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 5287936
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=E33<E34"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 255
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
    "=OR(E33="""",E33=0)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent1
    .TintAndShade = 0.799981688894314
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.Copy
Range("E33:Q33").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

Range("E39").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=E39>E40"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 5287936
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=E39<E40"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 255
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
    "=OR(E39="""",E39=0)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent1
    .TintAndShade = 0.799981688894314
End With
Selection.FormatConditions(1).StopIfTrue = False

Selection.Copy
Range("E39:Q39").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

End If
Next sht
csheet.Activate
Application.ScreenUpdating = True
End Sub 
subcon()
尺寸sht作为工作表,C作为工作表
呼叫removecond
Application.ScreenUpdating=False
设置csheet=ActiveSheet
对于ActiveWorkbook.工作表中的每个sht
如果短小可见,则
短促激活
范围(“E8”)。选择
Selection.FormatConditions.Add类型:=xlExpression,公式1:=“=E8>E9”
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
带选择。格式条件(1)。内部
.PatternColorIndex=xlAutomatic
.颜色=5287936
.TintAndShade=0
以
Selection.FormatConditions(1).StopIfTrue=False
Selection.FormatConditions.Add类型:=xlExpression,公式1:=“=E8E12”
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
带选择。格式条件(1)。内部
.PatternColorIndex=xlAutomatic
.颜色=5287936
.TintAndShade=0
以
Selection.FormatConditions(1).StopIfTrue=False
Selection.FormatConditions.Add类型:=xlExpression,公式1:=“=E11E18”
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
带选择。格式条件(1)。内部
.PatternColorIndex=xlAutomatic
.颜色=5287936
.TintAndShade=0
以
Selection.FormatConditions(1).StopIfTrue=False
Selection.FormatConditions.Add类型:=xlExpression,公式1:=“=E17E21”
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
带选择。格式条件(1)。内部
.PatternColorIndex=xlAutoma