ich habe hier eine bedingte Formatierung und würde die nun gerne in ein Makro umwandeln.... Änderungen an einem Makro gehen nun mal schneller als bei einer bedingten Formatierung die schon Dutzend mal hin und her kopiert wurde...
Wenn man hier helfend unter die Arme greifen könnte, wäre ich sehr dankbar...
Alles Nötige steht in angehängter Datei https://www.herber.de/bbs/user/128610.xlsm
Als Antwort von fcs erhielt ich folgendes:
Sub prcBdengteFormatierung()
Dim wks As Worksheet, rngFormat As Range
Set wks = ActiveSheet
Set rngFormat = wks.Range("E5:AD72")
With rngFormat
.Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=(REST(SPALTE();2)=0)*(REST(ZEILE();2)=1)*(D5>0)*((D5""CW"")*(D5>=D6)*(D6"""")"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = VBA.RGB(red:=0, green:=255, blue:=0)
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=(REST(SPALTE();2)=0)*(REST(ZEILE();2)=1)*((D6="""")*((D5-$A$92)=0))"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = VBA.RGB(red:=255, green:=255, blue:=0)
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=(REST(SPALTE();2)=0)*(REST(ZEILE();2)=1)*(E5=""a"")"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = VBA.RGB(red:=0, green:=255, blue:=0)
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
End With
End Sub
Mein Problem nun:Ich habe den Code jetzt in Modul1 kopiert, allerdings bekomme ich bei der Ausführung direkt _ die Fehler Meldung: Laufzeitfehler '5' Ungültiger Prozeduraufruf oder ungültiges Argument.
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=(REST(SPALTE();2)=0)*(REST(ZEILE();2)=1)*(E5>0)*((E5=""CW"")*(E5>=E6)*(E6"")"
Hier bleibt der Code (laut Debugger) stehen. Auch die Änderung zu Englisch ( MOD, ROW und COLUMN) half nicht.
Gibt es auch eine Möglichkeit den Code bei Worksheet_Change auf nur einem Bestimmten Tabellenblatt laufen zu lassen ?