Default value in Listbox

C

Caspar

Hi,

I have created a Listbox in a Userform with a single
column of information containing the months in a year
(1,2,...,12).
Is it possible to set the actual month as a default value
in the Listbox?

Thanks for all answers!
 
H

Harald Staff

Something like:

Private Sub UserForm_Initialize()
Dim L As Long
For L = 1 To 12
ListBox1.AddItem _
StrConv(Format(DateSerial(2000, L, 1), _
"mmmm"), vbProperCase)
Next
ListBox1.ListIndex = Month(Date) - 1
End Sub

Note that a listbox's 1st entry is number 0, so that's where the -1 part
comes in. You get used to it pretty fast.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top