Folgendes "Problem" liegt vor:
(Beispieltabelle liegt hier: https://www.herber.de/bbs/user/151158.xlsm)
Ich habe eine Tabelle in der alle Zeilen mit einem Datum (Spalte B) versehen sind, hier ist eine bedingte Formatierung nötig, die mir ausgiebt ob das Datum schon in der Vergangenheit, oder innerhalb der nächsten 10 oder 14 Tage liegt.
(Die klassische bedingte Formatierung hat sich leider nicht als so ganz praktisch auf Dauer erwiesen, da die Liste nicht gerade statisch ist)
Ich bekomme es hin, den Wert anhant einer zweiten Spalte D einzufärben, wo die Differenz in Tagen berechnet wird, aber nicht in der Datumsspalte selber.
Würde mir den Umweg über Spalte D gene sparen.
Kann ich also meine Formula1:="14" durch etwas wie Formula1:="DATUMSDIFFERENZ IN TAGEN = 14" ersetzen?
Vielen Dank schon mal?
Sub WerteEinfärben()
Dim rngBereich As Range
Dim rngBereich2 As Range
With Tabelle1
Set rngBereich = .Range("D:D") 'definiert Bereich'
rngBereich.FormatConditions.Delete 'löscht vorherige Formatierung'
rngBereich.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, Formula1:="14" 'Setzt Bedingung für neue Formatierung'
rngBereich.FormatConditions(rngBereich.FormatConditions.Count).SetFirstPriority
With rngBereich.FormatConditions(1)
.Font.ColorIndex = 10 'Schriftfarbe'
.Interior.ColorIndex = 35 'Hintergrundfarbe'
End With
Set rngBereich = .Range("D:D")
rngBereich.FormatConditions.Add Type:=xlCellValue, Operator:=xlLessEqual, Formula1:="14"
rngBereich.FormatConditions(rngBereich.FormatConditions.Count).SetFirstPriority
With rngBereich.FormatConditions(1)
.Font.ColorIndex = 29
.Interior.ColorIndex = 24
End With
Set rngBereich = .Range("D:D")
rngBereich.FormatConditions.Add Type:=xlCellValue, Operator:=xlLessEqual, Formula1:="10"
rngBereich.FormatConditions(rngBereich.FormatConditions.Count).SetFirstPriority
With rngBereich.FormatConditions(1)
.Font.ColorIndex = 49
.Interior.ColorIndex = 34
End With
Set rngBereich = .Range("D:D")
rngBereich.FormatConditions.Add Type:=xlCellValue, Operator:=xlLessEqual, Formula1:="0"
rngBereich.FormatConditions(rngBereich.FormatConditions.Count).SetFirstPriority
With rngBereich.FormatConditions(1)
.Font.ColorIndex = 3
.Interior.ColorIndex = 38
End With
End With
End Sub