Tom’s Tutorials For Excel: ListBox Days & ComboBox Months

Tom’s Tutorials For Excel: ListBox Days & ComboBox Months

In your userform’s module, this Initialize event code populates a ListBox with days of the week, and a ComboBox with months of the year, as seen by example in the picture.



Private Sub UserForm_Initialize()

'Populate a ListBox with days of the week.
Dim myarray As Variant
myarray = _
Split("Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday", "|")
ListBox1.List = myarray

'Populate a ComboBox with months of the year.
Dim i%
For i = 1 To 12
ComboBox1.AddItem Format(DateSerial(2000, i, 1), "MMMM")
Next i

End Sub

Share Button
Posted in Tom's Tutorials for Excel
Tags: , , , , , , , , , , , , , ,
One comment on “Tom’s Tutorials For Excel: ListBox Days & ComboBox Months
  1. Abdul Sabrah says:

    Public Sub PopulateDays()
    ‘Populate a ListBox with days of the week.
    Dim myarray(1 To 7) As Variant
    Dim i As Long
    For i = 1 To 7
    myarray(i) = WeekdayName(i, False)
    Next
    Me.ListBox1.List = myarray

    Dim mntharry(1 To 12) As String
    For i = 1 To 12
    mntharry(i) = MonthName(i, False)
    Next
    Me.ComboBox1.List = mntharry
    End Sub

Leave a Reply

Your email address will not be published.

*

  • Facebook
  • Twitter
  • Instagram
  • Linkedin
  • Youtube