ich komme mal wieder nicht weiter und hoffe auf eure Hilfe. Folgendes Problem:
Ich habe ein Blatt mit vielen bedingten Formatierungen. Davon müssen einige vor dem Druck des Blattes entfernt und danach wieder gesetzt werden.
Ich habe mal per Makroaufzeichnung den Code für die bedingten Formatierungen erstellt.
Sub bedForm()
Application.Goto Reference:="StdBereich01"
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=""K"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 8124360
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=""EK"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 8124360
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=""FS"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 15506431
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=""P"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 14277081
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=""NT"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 14277081
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=""X"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 14277081
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Application.Goto Reference:="StdBereich02"
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=ZÄHLENWENN(Feiertage;C$7)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 14281213
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=C$7="""""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.Pattern = xlNone
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=WOCHENTAG(C$7;2)>5"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 14277081
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
End Sub
1. Problem: Wie kann man den Code für den StdBereich01 vereinfachen, da ja mehrere Werte die gleiche Formatierung erhalten.
2. Wie kann ich die Formatierungen des StdBereich01 vor dem Druck entfernen und nach dem Druck wieder setzen.
So sehen die Formatierungen aus:
Zellwert= "K" oder "EK" Hintergrund = 200 247 123 ( 8124360 ) =StdBereich01
Zellwert= "FS" Hintergrund = 255 155 236 ( 15506431 ) =StdBereich01
Zellwert= "P" oder "NT" oder "X" Hintergrund = 217 217 217 ( 14277081 ) =StdBereich01
Zellwert= "U" oder "S" Hintergrund = 253 233 217 ( 14281213 ) =StdBereich01
Zellwert= "?" Hintergrund = 255 0 0 ( 255 ) =StdBereich01
Zellwert= "UF" Hintergrund = 251 212 179 ( 11785467 ) =StdBereich01
Zellwert= "KoN" oder "EKoN" Hintergrund = 255 255 0 ( 65535 ) =StdBereich01
Formel: =ZÄHLENWENN(Feiertage;C$7) Hintergrund = 253 233 217 ( 14281213 ) =StdBereich02
Formel: =C$7="" Hintergrund = ohne =StdBereich02
Formel: =WOCHENTAG(C$7;2)>5 Hintergrund = 217 217 217 ( 14277081 ) =StdBereich02
Noch anzumerken ist, dass sich beide Bereiche im wesentlich überschneiden.
Ich denke mal es müsste so ablaufen:
1. Alle bedingten Formatierungen Löschen
2. die Bedingten Formatierungen des StdBereich02 wieder setzen, die sollen im Ausdruck erscheinen
3. drucken
4. die Bedingten Formatierungen des StdBereich01 wieder setzen
Kann mir Jemand helfen, hab von VBA keine Ahnung.
Vielen Dank!
mfg, Andreas