Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am new to VBA coding. I just made a program where I created a Userform having three ComboBox viz., Day, Month and Year.
I have successfully managed to fill those with required data. In ComboBoxYear, the dropdown year starts with least (i.e., 1960, which I have kept), and ends with current year (i.e., 2017).
I want to change this dropdown list, starting from 2017, and goes on decreasing till 1960.
Below is the code part where I have coded for inputs for DDMMYYY.

What I have tried:

VB
Private Sub UserForm_Initialize()
Dim i As Integer
With UserForm1
For i = 1 To 31
    .ComboBoxDay.AddItem (i)
    Next
End With

Dim ctr As Long
For ctr = 1 To 12
Me.ComboBoxMonth.AddItem Format(DateSerial(YYYY, ctr, DD), "mmm")
Next ctr

With UserForm1
For i = 1960 To 2017
    .ComboBoxYear.AddItem (i)
    Next

End With
End Sub
Posted
Updated 3-Oct-17 8:20am
v2

1 solution

Try this

VB
With UserForm1
For i = 2017 To 1960 Step -1
    .ComboBoxYear.AddItem (i)
    Next
 
End With
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900