Die Funktion formatiert Datumsfelder in einem definierten Bereich. Die Formatierung erfolgt aus Basis der einzelnen Tage (Mo...SO).
Sub setDateColor()
On Error GoTo ErrorExit
' RGB (n, n, n)
' rot (255, 0, 0)
' weiß (255, 255, 255)
' SW (0, 0, 0)
' hell-grau (217, 217, 217)
' grau (128, 128, 128)
Dim tmpStartZeile As Integer
Dim tmpStartSpalte As Integer
Dim tmpEndeZeile As Integer
Dim tmpEndeSpalte As Integer
tmpStartZeile = 4
tmpStartSpalte = 1
tmpEndeZeile = 50
tmpEndeSpalte = 2
For Each cell In Range(Cells(tmpStartZeile, tmpStartSpalte), Cells(tmpEndeZeile, tmpEndeSpalte))
If IsDate(cell.Value) Then
Select Case Weekday(cell.Value)
Case 1 ' Sonntag
Range(cell.Address).Font.Bold = True
Range(cell.Address).Font.Color = RGB(255, 0, 0)
Range(cell.Address).Interior.Color = RGB(217, 217, 217)
Case 2 ' Montag
Range(cell.Address).Font.Bold = False
Range(cell.Address).Font.Color = RGB(0, 0, 0)
Range(cell.Address).Interior.Color = RGB(255, 255, 255)
Case 3 ' Dienstag
Range(cell.Address).Font.Bold = False
Range(cell.Address).Font.Color = RGB(0, 0, 0)
Range(cell.Address).Interior.Color = RGB(255, 255, 255)
Case 4 ' Mittwoch
Range(cell.Address).Font.Bold = False
Range(cell.Address).Font.Color = RGB(0, 0, 0)
Range(cell.Address).Interior.Color = RGB(255, 255, 255)
Case 5 ' Donnerstag
Range(cell.Address).Font.Bold = False
Range(cell.Address).Font.Color = RGB(0, 0, 0)
Range(cell.Address).Interior.Color = RGB(255, 255, 255)
Case 6 ' Freitag
Range(cell.Address).Font.Bold = False
Range(cell.Address).Font.Color = RGB(0, 0, 0)
Range(cell.Address).Interior.Color = RGB(255, 255, 255)
Case 7 ' Samstag
Range(cell.Address).Font.Bold = False
Range(cell.Address).Font.Color = RGB(255, 0, 0)
Range(cell.Address).Interior.Color = RGB(217, 217, 217)
End Select
End If
Next cell
Exit Sub
ErrorExit:
MsgBox Error(Err), vbInformation, "Fehlermeldung (" & LTrim(Str(Err)) & ")"
Resume Next
End Sub