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

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
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,224,827
Messages
6,181,197
Members
453,022
Latest member
RobertV1609

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