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!
 

Some videos you may like

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

MrKowz

Well-known Member
Joined
Jun 30, 2008
Messages
6,653
Office Version
  1. 365
  2. 2016
Platform
  1. Windows

MrKowz

Well-known Member
Joined
Jun 30, 2008
Messages
6,653
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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:

MrKowz

Well-known Member
Joined
Jun 30, 2008
Messages
6,653
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Buuuuuumparoo!
 

MrKowz

Well-known Member
Joined
Jun 30, 2008
Messages
6,653
Office Version
  1. 365
  2. 2016
Platform
  1. Windows

ADVERTISEMENT

bump
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,133
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
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!
 

MrKowz

Well-known Member
Joined
Jun 30, 2008
Messages
6,653
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Perfect! Thank you much!
 

Watch MrExcel Video

Forum statistics

Threads
1,123,083
Messages
5,599,643
Members
414,326
Latest member
kfg1287

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
Top