0
我有一個問題: 我試圖做兩個不同的條件格式一次。 但它只適用於第二個。使用 林如果和ELSEIF,只有ENDIF 工作我必須寫得到解決它們兩者兼而有之?第一個之後呢?條件格式化vba與if
For Each cell In Range("A1:AA1")
If cell.Value = "GM WP6 Sensor Status" Then
Cells.FormatConditions.Delete
Columns("H:H").Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlNotEqual, _
Formula1:="=32671"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
'Selection.FormatConditions(1).StopIfTrue = False
Columns("H:H").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=LEN(TRIM(H1))=0"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.Pattern = xlNone
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Range("A1").Select
''''''''''''''''''''''''''Tikrina kita
ElseIf cell.Value = "GM WP6 Sensor Status light" Then
Cells.FormatConditions.Delete
Columns("I:I").Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlNotEqual, _
Formula1:="=32767"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Columns("I:I").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=LEN(TRIM(I1))=0"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.Pattern = xlNone
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Range("A1").Select
End If
Next cell
運行時錯誤5無效的過程調用或參數。在此:列(「H:H」)。FormatConditions.Add類型:= xlExpression,Formula1:= _ 「= AND(LEN(TRIM(H1))> 0,H1 <> 32671)」 –
我做一些更正它現在的工作:)謝謝@sktneer –
@SkirmanteValentaite不客氣! :) – sktneer