Ich versuche, einige bedingte Formatierung in VBA für Excel 2013 arbeiten zu bekommen. Die Ausführung des Codes sollte die Zelle (Innenfarbe) in Col N grün, wenn die Liste Validierung " Beende "und weiß zu jeder anderen Zeit. Die Zelle (innere Farbe) in Spalte O sollte rot werden, wenn die Listenüberprüfung in Spalte N "gehalten" ist und zu jeder anderen Zeit weiß ist.Excel VBA: Bedingte Formatierung - Interior Colors
Momentan erscheinen folgende Ergebnisse: 1. Col N und Col O sind weiß, wenn in der Listenvalidierung nichts ausgewählt ist. 2. Col N wird grün, wenn in der Listenvalidierung etwas ausgewählt ist. 3. Col O wird rot, wenn in Col N "Held" ausgewählt ist und wird wieder weiß, wenn in Col N noch etwas anderes ausgewählt ist.
4. Wenn in Spalte O etwas ausgewählt ist, wird die Zelle rot.
Mein aktueller Code ist (zusammen mit Abschnitten, die ich kommentiert habe aus):
'Add conditional format for column N. If Status is "Complete", color Status cell (col N) green (43).
With Worksheets(SheetNum & " - Work").Range("N2:N2000").Select
'Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=OR(($N2=""Not Started""),($N2=""In Queue""), ($N2=""In Work""), ($N2=""Held""), ($N2="" "")"
'Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlNotEqual, _
Formula1:="=($N2=""Complete"")"
'With Selection.FormatConditions(1)
'.Interior.ColorIndex = 2
'.StopIfTrue = True
'End With
'End With
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlNotEqual, _
Formula1:="=($N2=""Complete"")"
With Selection.FormatConditions(1)
.Interior.ColorIndex = 43
'.StopIfTrue = True
End With
End With
'Add conditional format for column O. If Status is "Held", color Held For cell (col O)
'red (3).
'With Worksheets(SheetNum & " - Work").Range("O2:O2000").Select
'Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlNotEqual, _
Formula1:="=OR(($N2=""Not Started""),($N2=""In Queue""), ($N2=""In Work""), ($N2=""Complete""))"
'Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=($N2=""Held"")"
'With Selection.FormatConditions(1)
'.Interior.ColorIndex = 2
'.StopIfTrue = True
'End With
With Worksheets(SheetNum & " - Work").Range("O2:O2000").Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlNotEqual, _
Formula1:="=($N2=""Held"")"
With Selection.FormatConditions(1)
.Interior.ColorIndex = 3
'.StopIfTrue = True
End With
End With
Auch kann jemand erklären, wenn Operator zu verwenden: = xlNotEqual vs Operator: = xlEqual? Diese scheinen zu funktionieren, was ich erwartet hätte.
Danke für jede Hilfe.