HERBERS Excel-Forum - das Archiv
Datumzeitraum in Combobox
Forster

Hallo,
kann mir jemand sagen, was bei dem Makro falsch ist?
VBA bringt den Fehler: "Konstanter Ausdruck erforderlich", damit ist das +30 beim Date gemeint.
Möchte eigentlich nur einen variablen Zeitraum in eine Combobox packen, ohne die Daten aus einem Excelblatt auslesen zu müssen.
Mein Code
Dim arr(Date To Date + 30)
Dim L As Long
ComboBox1.Clear
For L = Date To Date + 30
arr(L) = Format(L, "dd.mm.yyyy")
Next
ComboBox1.List = arr
Danke für Eure Hilfe
Gruß
Forster
AW: Datumzeitraum in Combobox
ransi

HAllo Foster
Probier mal so:


Private Sub CommandButton1_Click()
Dim arr(30)
Dim L As Integer
ComboBox1.Clear
For L = 0 To 29
    arr(L) = Format(Date + L, "dd.mm.yyyy")
Next
ComboBox1.List = arr
End Sub


ransi
AW: Datumzeitraum in Combobox
Forster

Hallo ransi,
geht aus auch mit negativem Datumswert, d. h. Heute 6.1.2007, möchte aber auch z. B. 15.12.2006 anzeigen, mit minus Zeichen gehts anscheinend nicht.
Weißt du noch einen Tipp?
Danke für deine schnelle Hilfe
Gruß
Forster
AW: Datumzeitraum in Combobox
ransi

HAllo
Hilft dir das hier weiter ?


Public Sub test()
Dim arr(30)
Dim L As Integer
Dim var
var = CDate("15.12.06")
ComboBox1.Clear
For L = 0 To 29
    arr(L) = Format(var + L, "dd.mm.yyyy")
Next
ComboBox1.List = arr
End Sub
Public Sub test1()
Dim arr(30)
Dim L As Integer
ComboBox1.Clear
For L = 0 To 29
    arr(L) = Format(Date - 20 + L, "dd.mm.yyyy")
Next
ComboBox1.List = arr
End Sub
Public Sub test2()
Dim arr(30)
Dim L As Integer
ComboBox1.Clear
For L = 0 To 29
    arr(L) = Format(Date - UBound(arr) + L, "dd.mm.yyyy")
Next
ComboBox1.List = arr
End Sub


ransi
AW: Datumzeitraum in Combobox
Forster

Hallo ransi,
hab's gerade ausprobiert, klappt super, genau wie ich es möchte.
Danke.
Gruß
Forster