ein ziemlich gutes Script bei der Anwendung von bedingter Formatierung gefunden.
Ich habe jetzt versucht es auf meine Bedürfnisse umzusstricken. Leider ohne Erfolg.
Ich möchte dass in Abhängigkeit des Bereichs ("C8:C500") sich der jeweilige Zellenhintergrund (A-O) für jede Bedingung in einer anderen Farbe färbt:
Bedingungen sind:
A-Class
B-Class
C-Class
E-Class
R-Class
Vito -10 seater =Farbe wie "Sprinter -15 seater"
Sprinter -15 seater
S-Class =Farbe wie "S-Class + Chauffeur"
S-Class + Chauffeur
leer Zelle= keine formatierung vornehmen
Ich stoße auf 2 Probleme:
Als erstes weiss ich nicht wie ich das Script dazu bringe die Zeile inkl. spalte A und B zu markieren
Mein zweites Problem ist das alles was über 1 Buchstaben hinausgeht nicht richtig erkannt wird. Also in meinen Fall alles.
Vielen Dank schonmal im voraus für Eure Tips und Ratschläge.
Anbei der Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
'* H. Ziplies *
'* 19.07.03; 30.10.03; 18.11.05 *
'* erstellt von Hajo.Ziplies@web.de *
'* http://Hajo-Excel.de/
' Fülfarbe
' für Schrift RaZelle.Font.ColorIndex
Dim RaBereich As Range, RaZelle As Range
' Bereich der Wirksamkeit
Set RaBereich = Range("C8:C500")
' noch mehr Bereiche
' Set RaBereich = Union(Range("C11:AG11 , C13:AG13, C15:AG15 , C17:AG17 , C19:AG19 , C21: _
AG21 , C27:AE27 , C29:AE29, C31:AE31, C33:AE33"), _
' Range("C35:AE35, C37:AE37, C43:AG43, C45:AG45 , C47:AG47 , C49:AG49 ,C51:AG51 , C53: _
AG53 , C59:AF59 , C61:AF61 , C63:AF63 , C65:AF65"), _
' Range("C67:AF67 , C69:AF69 , C75:AG75 , C77:AG77 , C79:AG79 , C81:AG81 , C83:AG83 , _
C85:AG85 ,C91:AF91 , C93:AF93 , C95:AF95 , C97:AF97"), _
' Range("C99:AF99 , C101:AF101, C107:AG107 , C109:AG109 , C111:AG111 , C113:AG113 , C115: _
_
AG115 , C117:AG117 , C123:AG123 , C125:AG125"), _
' Range("C127:AG127 , C129:AG129 , C131:AG131 , C133:AG133 , C139:AF139 , C141:AF141 , _
_
C143:AF143 , C145:AF145 , C147:AF147 , C149:AF149"), _
' Range("C155:AG155, C157:AG157 , C159:AG159 , C161:AG161 , C163:AG163 , C165:AG165 , _
C171:AF171 , C173:AF173 , C175:AF175 , C177:AF177 "), _
' Range("C179:AF179 , C181:AF181, C187:AG187 , C189:AG189 , C191:AG191 , C193:AG193 , _
C195:AG195 , C197:AG197"))
' ab Vesion XP braucht der Schutz nicht aufgehoben werden
' Formatierung bei Schutz kann über Dialog Schutz eingestellt werden
' ActiveSheet.Unprotect ("Passwort")
' Zelle die in dem Bereich liegen auf die Varible schreiben
' damit werden nur noch die Zellen bearbeitet die im vorgegeben Bereich liegen
' jede Zelladresse ist einzeln angegeben
Set RaBereich = Intersect(RaBereich, Range(Target.Address))
If RaBereich Is Nothing Then Exit Sub
For Each RaZelle In RaBereich
With Range(RaZelle.Address, RaZelle.Offset(0, 12).Address)
Select Case UCase(RaZelle.Value) ' UMWANDLUNG DER Eingabe in Großbuchstaben
Case "A-Class"
' rot
.Interior.ColorIndex = 2
'.Font.ColorIndex = 0
' Schriftfarbe automatisch
'.NumberFormat = "General"
' Zellenformat Standard
Case "B-Class"
' gelb
.Interior.ColorIndex = 5
'.Font.ColorIndex = 0
' Schriftfarbe automatisch
'.NumberFormat = "General"
' Zellenformat Standard
Case "C-Class"
' gelb
.Interior.ColorIndex = 7
'.Font.ColorIndex = 0
' Schriftfarbe automatisch
'.NumberFormat = "General"
' Zellenformat Standard
Case "E-Class"
' gelb
.Interior.ColorIndex = 6
'.Font.ColorIndex = 0
' Schriftfarbe automatisch
'.NumberFormat = "General"
' Zellenformat Standard
Case "R-Class"
' gelb
.Interior.ColorIndex = 9
'.Font.ColorIndex = 0
' Schriftfarbe automatisch
'.NumberFormat = "General"
' Zellenformat Standard
Case "S-Class"
' gelb
.Interior.ColorIndex = 10
'.Font.ColorIndex = 0
' Schriftfarbe automatisch
'.NumberFormat = "General"
' Zellenformat Standard
Case "S-Class + Chauffeur"
' gelb
.Interior.ColorIndex = 10
'.Font.ColorIndex = 0
' Schriftfarbe automatisch
'.NumberFormat = "General"
' Zellenformat Standard
Case "Vito -10 seater"
' gelb
.Interior.ColorIndex = 11
'.Font.ColorIndex = 0
' Schriftfarbe automatisch
'.NumberFormat = "General"
' Zellenformat Standard
Case "Sprinter -15 seater"
' gelb
.Interior.ColorIndex = 10
'.Font.ColorIndex = 0
' Schriftfarbe automatisch
'.NumberFormat = "General"
' Zellenformat Standard
Case Else
' Keine
.Interior.ColorIndex = xlNone
'.Font.ColorIndex = 0
' Schriftfarbe automatisch
'.NumberFormat = "General"
' Zellenformat Standard
End Select
End With
Next RaZelle
' ActiveSheet.protect ("Passwort")
Set RaBereich = Nothing
End Sub