Zellen per VBA farbig markieren - Hilfe beim code
Betrifft: Zellen per VBA farbig markieren - Hilfe beim code
von: toteitote
Geschrieben am: 08.09.2014 20:28:08
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
 |
Betrifft: AW: Zellen per VBA farbig markieren - Hilfe beim code
von: ransi
Geschrieben am: 08.09.2014 20:59:35
HAllo
Lade doch mal die Tabelle hoch.
Mein Excel tut sich etwas schwer damit einen Screenshot zu bearbeiten.
ransi
Betrifft: AW: Zellen per VBA farbig markieren - Hilfe beim code
von: toteitote
Geschrieben am: 08.09.2014 21:03:57
https://www.herber.de/bbs/user/92530.xlsm
Betrifft: AW: Zellen per VBA farbig markieren - Hilfe beim code
von: toteitote
Geschrieben am: 08.09.2014 21:09:02
Danke schonmal im Vorraus!
Tiemo
Betrifft: AW: Zellen per VBA farbig markieren - Hilfe beim code
von: toteitote
Geschrieben am: 08.09.2014 22:48:49
Hi, Ich habe noch ein paar Kleinigkeiten an dem Code geändert... Je nach Änderung gab es verschiedene Fehlermeldungen: die Gesamte Spalte war geloopt; eine einzeilne Zelle wurde geloopt oder der Output hat nicht die Zelle betroffen, in die ich einen target-text eingegeben habe sondern die darauf folgende per 'Else:' command in Weiß gefärbt.
Ich würde die Formeln gerne zum laufen bringen, aber das passt noch nicht. Auch fehlt mir noch der Befehl, den Zell-Farbinhalt zu eliminieren sobald ich den Wert lösche. Bitte um Hülf:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
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 = 2
End If
End Sub
 |
Betrifft: ...Und warum dann nicht BedingtFormat, ...
von: Luc:-?
Geschrieben am: 08.09.2014 23:17:10
…Tiemo,
da hättest du das FarbRückstellProblem gar nicht erst?!
Besser informiert mit …
Betrifft: AW: ...Und warum dann nicht BedingtFormat, ...
von: toteitote
Geschrieben am: 09.09.2014 03:37:29
Das lässt sich nicht bearbeiten mit mehr als drei variablen und mit dem automatischen cell-color erase funktioniert auch nicht, soweit mir bekannt ist...
Betrifft: AW: ..warum soll das nicht gehen
von: Ewald
Geschrieben am: 09.09.2014 14:53:50
Hallo,
dafür gibt es die Oder-Formel
Gruß Ewald
Beiträge aus den Excel-Beispielen zum Thema "Zellen per VBA farbig markieren - Hilfe beim code"