Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default Loading a Combo Box with the months of the year

Hi,

I'm trying to make a form (using Excel VBA) that will offer a drop-
down combo box to choose a month.

The only way I've been able to do this is to have a sheet containing
all the months, and load the list from there. If possible though, I'd
like to avoid having nearly-empty sheets hanging around.

Is there any way to load the months directly into the combo box list
through VBA?

Thanks!
- Eric

  #2   Report Post  
Posted to microsoft.public.excel.misc
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Loading a Combo Box with the months of the year

Perhaps something similar to this could be used. Double click on your
userform and paste the code into the code module. Change "ComboBox1" to
whatever name your combobox is.

Private Sub UserForm_Initialize()
Dim i As Long
Dim varMonths As Variant

varMonths = Array("Jan", "Feb", "Mar", _
"Apr", "May", "Jun", "Jul", "Aug", _
"Sep", "Oct", "Nov", "Dec")

For i = LBound(varMonths) To UBound(varMonths)
Me.ComboBox1.AddItem varMonths(i)
Next i

End Sub


"Eclypse" wrote:

Hi,

I'm trying to make a form (using Excel VBA) that will offer a drop-
down combo box to choose a month.

The only way I've been able to do this is to have a sheet containing
all the months, and load the list from there. If possible though, I'd
like to avoid having nearly-empty sheets hanging around.

Is there any way to load the months directly into the combo box list
through VBA?

Thanks!
- Eric


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default Loading a Combo Box with the months of the year

That worked a charm - Thanks a lot! I've been looking for the answer
to that for months. :-)

Thanks again,

Cheers,
- Eric


On Apr 12, 3:22 pm, JMB wrote:
Perhaps something similar to this could be used. Double click on your
userform and paste the code into the code module. Change "ComboBox1" to
whatever name your combobox is.


*snip*

  #4   Report Post  
Posted to microsoft.public.excel.misc
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Loading a Combo Box with the months of the year

Good to hear that worked for you.

"Eclypse" wrote:

That worked a charm - Thanks a lot! I've been looking for the answer
to that for months. :-)

Thanks again,

Cheers,
- Eric


On Apr 12, 3:22 pm, JMB wrote:
Perhaps something similar to this could be used. Double click on your
userform and paste the code into the code module. Change "ComboBox1" to
whatever name your combobox is.


*snip*


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Loading a Combo Box with the months of the year

A couple more options:

Option Explicit
Private Sub UserForm_Initialize()
Dim iCtr As Long
For iCtr = 1 To 12
Me.ComboBox1.AddItem Format(DateSerial(2007, iCtr, 1), "mmm")
Next iCtr
End Sub


Or if you're using xl2002 or above (IIRC), you could use MonthName:

Option Explicit
Private Sub UserForm_Initialize()
Dim iCtr As Long
For iCtr = 1 To 12
Me.ComboBox1.AddItem MonthName(iCtr, abbreviate:=True)
Next iCtr
End Sub

Eclypse wrote:

Hi,

I'm trying to make a form (using Excel VBA) that will offer a drop-
down combo box to choose a month.

The only way I've been able to do this is to have a sheet containing
all the months, and load the list from there. If possible though, I'd
like to avoid having nearly-empty sheets hanging around.

Is there any way to load the months directly into the combo box list
through VBA?

Thanks!
- Eric


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default Loading a Combo Box with the months of the year

Thanks Dave, that's a particularly slick way of doing it.

Cheers for your help!
- Eric


On Apr 13, 12:17 am, Dave Peterson wrote:
A couple more options:

Option Explicit
Private Sub UserForm_Initialize()
Dim iCtr As Long
For iCtr = 1 To 12
Me.ComboBox1.AddItem Format(DateSerial(2007, iCtr, 1), "mmm")
Next iCtr
End Sub


  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default Loading a Combo Box with the months of the year

I was just offered a particularly nice suggestion, thought I'd post it
here for the benefit of others:

Me.ComboBox1.List() = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec")

That's it!

Thanks both of you again for your help.

Cheers!

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Year-Days-Months Steve Excel Worksheet Functions 10 September 3rd 06 07:05 AM
Within 6 months, Within 1 year and so on... MER Excel Discussion (Misc queries) 1 August 2nd 06 08:05 PM
Locate particular months sale with year Rao Ratan Singh New Users to Excel 2 March 3rd 06 06:07 AM
how do I set up an entry so that 3 months or one year later Excel. jhg1226 Excel Worksheet Functions 0 March 11th 05 07:49 PM
How do i change 15 months to read 1 year and 3 months? Marty Excel Discussion (Misc queries) 1 February 17th 05 11:21 PM


All times are GMT +1. The time now is 10:24 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"