ich habe für eine größere Excel-Tabelle eine Bedingte Formatierung per VBA vorgehabt. Bei bestimmten Eingaben sollen die Zellen entsprechend gefärbt werden. Leider bekomme ich bei dem Code die Fehlermeldung "Laufzeitfehler 1004 - Die Interior-Eigenschaft des Range-Objektes kann nicht zugeordnet werden.". Ich hoffe mir kann dabei jemand helfen:
Private Sub Worksheet_Change(ByVal Target As Range)
ERRORHANDLER:
Application.EnableEvents = True
' Füllfarbe
' für Schrift RaZelle.Font.ColorIndex
Dim RaBereich As Range ' Variable für Bereich
Dim RaZelle As Range ' Variable für Zelle
' Bereich der Wirksamkeit
Set RaBereich = Range("G1:G500")
Set RaBereich = Intersect(RaBereich, Range(Target.Address))
If Not RaBereich Is Nothing Then
'ActiveSheet.Unprotect ("Passwort")
For Each RaZelle In RaBereich
With RaZelle
Select Case UCase(.Value) ' Umwandlung der Eingabe in Großbuchstaben
Case "EPM"
.Interior.Color = RGB(83, 141, 213)
.Font.Color = RGB(255, 255, 0)
.Font.FontStyle = "Bold Italic"
.HorizontalAlignment = xlCenter
.Cells = UCase(.Value)
Case "GEPLANT"
.Interior.Color = RGB(255, 255, 0)
.Font.Color = RGB(255, 0, 0)
.Font.FontStyle = "Bold Italic"
.HorizontalAlignment = xlCenter
.Cells = UCase(.Value)
Case "INFO"
.Interior.Color = RGB(255, 0, 0)
.Font.Color = RGB(255, 255, 255)
.Font.FontStyle = "Bold Italic"
.HorizontalAlignment = xlCenter
.Cells = UCase(.Value)
Case Else
.Font.ColorIndex = xlAutomatic
.Interior.ColorIndex = xlAutomatic
.Cells.Style = "Normal"
.Font.Color = 0
.NumberFormat = "General"
End Select
End With
Next RaZelle
'ActiveSheet.protect ("Passwort")
End If
Set RaBereich = Nothing ' Variable leeren
End Sub