Auto-Populating a dropbox in a userform

MrKowz

Well-known Member
Joined
Jun 30, 2008
Messages
6,653
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Is there a way to populate a dropbox in a user form that has years in it starting from 2008 until the current year?

It seems like a dumb thing to do right now, but this is a macro that will be used for many years to come for this company, and I want to make the userform idiot-proof.

For example: This year, I only want the dropbox to show 2008... next year I want it to show 2008 and 2009. In the year 2014, I want it to show 2008, 2009, 2010, 2011, 2012, 2013, 2014. And so on.

If this is possible, and someone has coding for it, if I could also get instructions on where to place it in a macro, that would be great. Currently I use the following macro to call my userform:

Code:
Sub eTPAProcessingPerformance()
ETPAREPORT.Show
End Sub

Thank you!
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
bump

Is it possible to do this?

I do not know how to populate a dropbox on a userform anyway, but I was thinking maybe I could do a while loop like this pseudocode.

Current Year = year
While year>2007
populatebox with year
year = year - 1
loop
 
Last edited:
Upvote 0
Right-click the userform, choose View Code and paste this in:
Code:
Private Sub UserForm_Initialize()
   Dim lngYear
   For lngYear = 2008 To Year(Date)
      Me.ComboBox1.AddItem lngYear
   Next lngYear
End Sub
replacing Combobox1 with the name of your combobox!
 
Upvote 0

Forum statistics

Threads
1,214,579
Messages
6,120,365
Members
448,956
Latest member
Adamsxl

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top