Gruppe
Ereignis
Problem
Wie kann ich durch Eingabe der Monats- bzw. Jahreszahl automatisch die Tage als Zahl und im Format DDD eintragen lassen. Die Routine soll automatisch die Anzahl der Tage erkennen und die Wochenenden farbig hinterlegen.
ClassModule: Tabelle2
Private Sub Worksheet_Change(ByVal Target As Range)
Dim lDay As Long, lStart As Long, lEnd As Long
Dim iDay As Integer
If Target.Address <> "$B$1" And _
Target.Address <> "$D$1" Then Exit Sub
Application.EnableEvents = False
On Error GoTo ERRORHANDLER
With Rows("2:3")
.ClearContents
.ClearFormats
.HorizontalAlignment = xlCenter
End With
lStart = DateSerial(Range("D1").Value, Range("B1").Value, 1)
lEnd = DateSerial(Range("D1").Value, Range("B1").Value + 1, 0)
For lDay = lStart To lEnd
iDay = iDay + 1
Cells(2, iDay).Value = iDay
Cells(3, iDay).Value = Format(lDay, "dddd")
If Weekday(lDay) = 7 Then
Cells(3, iDay).Interior.ColorIndex = 34
ElseIf Weekday(lDay) = 1 Then
Cells(3, iDay).Interior.ColorIndex = 35
End If
Next lDay
Me.Name = Format(DateSerial(1, Range("B1").Value, 1), "mmmm")
ERRORHANDLER:
Application.EnableEvents = True
End Sub