Zellen per VBA farbig markieren - Hilfe beim code
08.09.2014 20:28:08
toteitote
Hi, ich habe die Grundlage von dem code von 'stackoverflow' kopiert und möchte ihn nun praktisch utilisieren. Leider komme ich nicht weiter und hoffe mir kann geholfen werden...
http://www.pic-upload.de/view-24541374/Excel-VBA-Anwendung.jpg.html
http://www.pic-upload.de/view-24541459/VBA-Cockpit.jpg.html
Ich möchte, dass die im Upload markierten Farben in der markierten Spalte Anwendung finden. Gedacht ist, dass bei Eingabe der Label-Codes sich die Zellfarbe entsprechend ändert, auch dass bei Löschung des Eintrages wieder auf Weiß wechselt. Bitte um Korrektur des Codes und evtl. Lösungsansätze, wie man die Befehle bündeln/kürzen kann.
Der Code soweit ich ihn bearbeitet habe:
Sub ConditionalFormatting()
Do Until IsEmpty(ActiveCell.Text)
If ActiveCell.Text = "E1" Then
ActiveCell.Interior.ColorIndex = 10
ElseIf ActiveCell.Text = "E2" Then
ActiveCell.Interior.ColorIndex = 10
ElseIf ActiveCell.Text = "E3" Then
ActiveCell.Interior.ColorIndex = 10
ElseIf ActiveCell.Text = "EE1" Then
ActiveCell.Interior.ColorIndex = 10
ElseIf ActiveCell.Text = "EE2" Then
ActiveCell.Interior.ColorIndex = 10
ElseIf ActiveCell.Text = "EE3" Then
ActiveCell.Interior.ColorIndex = 10
ElseIf ActiveCell.Text = "EE4" Then
ActiveCell.Interior.ColorIndex = 10
ElseIf ActiveCell.Text = "T1" Then
ActiveCell.Interior.ColorIndex = 28
ElseIf ActiveCell.Text = "T2" Then
ActiveCell.Interior.ColorIndex = 28
ElseIf ActiveCell.Text = "T3" Then
ActiveCell.Interior.ColorIndex = 28
ElseIf ActiveCell.Text = "T4" Then
ActiveCell.Interior.ColorIndex = 28
ElseIf ActiveCell.Text = "T5" Then
ActiveCell.Interior.ColorIndex = 28
ElseIf ActiveCell.Text = "TT1" Then
ActiveCell.Interior.ColorIndex = 28
ElseIf ActiveCell.Text = "TT2" Then
ActiveCell.Interior.ColorIndex = 28
ElseIf ActiveCell.Text = "TT3" Then
ActiveCell.Interior.ColorIndex = 28
ElseIf ActiveCell.Text = "Z1" Then
ActiveCell.Interior.ColorIndex = 53
ElseIf ActiveCell.Text = "Z2" Then
ActiveCell.Interior.ColorIndex = 53
ElseIf ActiveCell.Text = "Z3" Then
ActiveCell.Interior.ColorIndex = 53
ElseIf ActiveCell.Text = "U1" Then
ActiveCell.Interior.ColorIndex = 54
ElseIf ActiveCell.Text = "U2" Then
ActiveCell.Interior.ColorIndex = 54
ElseIf ActiveCell.Text = "U3" Then
ActiveCell.Interior.ColorIndex = 54
ElseIf ActiveCell.Text = "K" Then
ActiveCell.Interior.ColorIndex = 56
ElseIf ActiveCell.Text = "TEC" Then
ActiveCell.Interior.ColorIndex = 56
ElseIf ActiveCell.Text = "NEC" Then
ActiveCell.Interior.ColorIndex = 56
ElseIf ActiveCell.Text = "Str" Then
ActiveCell.Interior.ColorIndex = 3
ElseIf ActiveCell.Text = "ENT" Then
ActiveCell.Interior.ColorIndex = 3
ElseIf ActiveCell.Text = "KUR" Then
ActiveCell.Interior.ColorIndex = 3
ElseIf ActiveCell.Text = "SOF" Then
ActiveCell.Interior.ColorIndex = 3
ElseIf ActiveCell.Text = "SER" Then
ActiveCell.Interior.ColorIndex = 3
ElseIf ActiveCell.Text = "ORG" Then
ActiveCell.Interior.ColorIndex = 3
ElseIf ActiveCell.Text = "RE" Then
ActiveCell.Interior.ColorIndex = 3
Else: ActiveCell.Interior.ColorIndex = 1
End If
ActiveCell.Offset(1, 0).Select
Loop
End Sub