Ich habe derzeit diesen Code unten. Wenn die Zelle leer ist, ist die Füllung grün (4). Wenn die Zelle nicht leer ist, wird keine Füllung angezeigt. Aber was, wenn ich meine Zelle (0,3) mit gelb füllen möchte, wenn der Zellenwert = "JA"? Derzeit haben Sie ein Dropdown-Menü für "JA" oder "NEIN".So wenden Sie die Füllfarbe in Abhängigkeit vom Zellenwert an VBA
Private Sub worksheet_change(ByVal Target As Range)
If Not Intersect(Target, Range("A:A")) Is Nothing Then
ActiveSheet.Unprotect
If Target = "YES" Then
For i = 1 To 9
With Target.Offset(0, i)
.Locked = False
.FormatConditions.Add Type:=xlExpression, Formula1:="=ISBLANK(" & Target.Offset(0, i).Address & ")"
With .FormatConditions(.FormatConditions.Count)
.SetFirstPriority
.Interior.ColorIndex = 4
End With
End With
Next i
'==============================================================================================================
'==============================================================================================================
ElseIf Target = "NO" Then
For i = 10 To 15
With Target.Offset(0, i)
.Locked = False
.FormatConditions.Add Type:=xlExpression, Formula1:="=ISBLANK(" & Target.Offset(0, i).Address & ")"
With .FormatConditions(.FormatConditions.Count)
.SetFirstPriority
.Interior.ColorIndex = 4
End With
End With
Next i
Else
For i = 1 To 15
With Target.Offset(0, i)
.Value = ""
.Locked = True
.FormatConditions.Delete
End With
Next i
End If
ActiveSheet.Protect
End If
End Sub
Es gibt einen Unterschied zwischen einer Zelle und einem Offset, die man meinen Sie ? (Es gibt auch keine 'Zelle (0,27)', der Index startet '1' –