Lasersword
Cadet 4th Year
- Registriert
- Jan. 2008
- Beiträge
- 123
Hallo ihr VBA-Profis,
ich hab ein kleines Problem:
Da Excel bei der "Bedingten Formatierung" nur 3 Möglichkeiten bietet,
habe ich versucht, mir einen VBA-Code zusammenzubasteln.
Ich habe von VBA nicht wirklich viel Ahnung, aber der Code funktioniert
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("B:B")) Is Nothing Then
Else
If Target.Value = "Text1" Then
Target.Cells.Interior.ColorIndex = 3
Else
If Target.Value = "Text2" Then
Target.Cells.Interior.ColorIndex = 6
Else
If Target.Value = "Text3" Then
Target.Cells.Interior.ColorIndex = 34
Else
If Target.Value = "Text4" Then
Target.Cells.Interior.ColorIndex = 34
Else
If Target.Value = "Text5" Then
Target.Cells.Interior.ColorIndex = 3
Else
If Target.Value = "Text6" Then
Target.Cells.Interior.ColorIndex = 3
Else
If Target.Value = "Text7" Then
Target.Cells.Interior.ColorIndex = 3
Else
If Target.Value = "Text8" Then
Target.Cells.Interior.ColorIndex = 3
Else
If Target.Value = "Text9" Then
Target.Cells.Interior.ColorIndex = 34
Else
If Target.Value = "Text10" Then
Target.Cells.Interior.ColorIndex = 35
Else
If Target.Value = "Text11" Then
Target.Cells.Interior.ColorIndex = 4
Else
If Target.Value = "Text12" Then
Target.Cells.Interior.ColorIndex = 6
Else
If Target.Value = "Text13" Then
Target.Cells.Interior.ColorIndex = 6
Else
If Target.Value = "Text14" Then
Target.Cells.Interior.ColorIndex = 6
Else
If Target.Value = "Text15" Then
Target.Cells.Interior.ColorIndex = 45
Else
If Target.Value = "Text16" Then
Target.Cells.Interior.ColorIndex = 4
Else
If Target.Value = "Text17" Then
Target.Cells.Interior.ColorIndex = 4
Else
Target.Cells.Interior.ColorIndex = 0
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End Sub
Wenn ich die einzelnen Werte in der Spalte B eintrage, macht er mir auch die Formatierung.
Allerdings läuft der Befehl auf einen Fehler, wenn ich mehrere Zellen markiere und dann "Enfernen" drücke.
Laufzeitfehler '13'
Typen unverträglich
Wenn ich jetzt den Debugger starte, sagt er mir, dass der Fehler im Befehl
If Target.Value = "Text1" Then
liegt.
Wo ist der Fehler?
Vielen Dank im Voraus.
ich hab ein kleines Problem:
Da Excel bei der "Bedingten Formatierung" nur 3 Möglichkeiten bietet,
habe ich versucht, mir einen VBA-Code zusammenzubasteln.
Ich habe von VBA nicht wirklich viel Ahnung, aber der Code funktioniert

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("B:B")) Is Nothing Then
Else
If Target.Value = "Text1" Then
Target.Cells.Interior.ColorIndex = 3
Else
If Target.Value = "Text2" Then
Target.Cells.Interior.ColorIndex = 6
Else
If Target.Value = "Text3" Then
Target.Cells.Interior.ColorIndex = 34
Else
If Target.Value = "Text4" Then
Target.Cells.Interior.ColorIndex = 34
Else
If Target.Value = "Text5" Then
Target.Cells.Interior.ColorIndex = 3
Else
If Target.Value = "Text6" Then
Target.Cells.Interior.ColorIndex = 3
Else
If Target.Value = "Text7" Then
Target.Cells.Interior.ColorIndex = 3
Else
If Target.Value = "Text8" Then
Target.Cells.Interior.ColorIndex = 3
Else
If Target.Value = "Text9" Then
Target.Cells.Interior.ColorIndex = 34
Else
If Target.Value = "Text10" Then
Target.Cells.Interior.ColorIndex = 35
Else
If Target.Value = "Text11" Then
Target.Cells.Interior.ColorIndex = 4
Else
If Target.Value = "Text12" Then
Target.Cells.Interior.ColorIndex = 6
Else
If Target.Value = "Text13" Then
Target.Cells.Interior.ColorIndex = 6
Else
If Target.Value = "Text14" Then
Target.Cells.Interior.ColorIndex = 6
Else
If Target.Value = "Text15" Then
Target.Cells.Interior.ColorIndex = 45
Else
If Target.Value = "Text16" Then
Target.Cells.Interior.ColorIndex = 4
Else
If Target.Value = "Text17" Then
Target.Cells.Interior.ColorIndex = 4
Else
Target.Cells.Interior.ColorIndex = 0
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End Sub
Wenn ich die einzelnen Werte in der Spalte B eintrage, macht er mir auch die Formatierung.
Allerdings läuft der Befehl auf einen Fehler, wenn ich mehrere Zellen markiere und dann "Enfernen" drücke.
Laufzeitfehler '13'
Typen unverträglich
Wenn ich jetzt den Debugger starte, sagt er mir, dass der Fehler im Befehl
If Target.Value = "Text1" Then
liegt.
Wo ist der Fehler?
Vielen Dank im Voraus.