Tom’s Tutorials For Excel: Populating a ComboBox For a Range of Years
This populates a UserForm ComboBox with years that start 10 years ago and end 10 years from now. The idea is to reasonably control the available year which a user can select. At each passing new year the code will adjust the relative list.
Private Sub UserForm_Initialize() Dim i%, j% j = Format(Date, "YYYY") For i = 1 To 21 ComboBox1.AddItem j - 10 j = j + 1 Next i End Sub
Just noting that it is possible to fill the ComboBox without using a loop…
Private Sub UserForm_Initialize()
ComboBox1.List = Evaluate(“ROW(” & Year(Now) – 10 & “:” & Year(Now) + 10 & “)”)