Gruppe
Ereignis
Problem
In Abhängigkeit der Auswahl im Gültigkeitsfeld B1 soll die Anzahl der Tage im Gültigkeitsfeld D1 festgelegt werden.
ClassModule: Tabelle1
Private Sub Worksheet_Change(ByVal Target As Range)
Dim intCounter As Integer
Dim strDays As String
If Target.Address <> "$B$1" Then Exit Sub
Select Case Range("B1").Value
Case "Januar", "März", "Mai", "Juli", "August", "Oktober", "Dezember"
For intCounter = 1 To 31
strDays = strDays & intCounter & ","
Next intCounter
Case "April", "Juni", "September", "November"
For intCounter = 1 To 30
strDays = strDays & intCounter & ","
Next intCounter
Case "Februar"
If Year(Date) Mod 4 = 0 Then
For intCounter = 1 To 29
strDays = strDays & intCounter & ","
Next intCounter
Else
For intCounter = 1 To 28
strDays = strDays & intCounter & ","
Next intCounter
End If
End Select
strDays = Left(strDays, Len(strDays) - 1)
With Range("D1").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=strDays
End With
End Sub