VBA _ Combox in form enter values

jakobt

Active Member
Joined
May 31, 2010
Messages
337
Have a userform 1 with a combobox1

Want to write VBA code 12 periods: Jan18 - Dec18 to be entered in the dropdown in the combox

How can I write VBA code for this?
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Try this:
Code:
Private Sub CommandButton2_Click()
'Modified  10/14/2018  10:06:42 AM  EDT
Dim i As Long
ComboBox1.Clear
For i = 1 To 12
ComboBox1.AddItem Format(DateAdd("M", i, "1.18,2018"), "MMM") & " 18"
Next
End Sub
 
Upvote 0
Another option
Code:
Private Sub UserForm_initialize()
   Dim i As Long
   For i = 1 To 12
      Me.ComboBox1.AddItem Format(i * 29, "mmm") & "18"
   Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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