Combobox problem

D

Dylan

I have a combobox on my sheet and I populate it with day numbers 1-31. The
problem is the numbers appear repeated 31 times in the list.

My code is
Private Sub ComboBox1_DropButtonClick()
Dim myArray1 As Variant
Dim myArray2 As Variant
Dim i As Long
myArray1 = Split("0|1|2|3|4|5|6|" _
& "7|8|9|10|11|12|" _
& "13|14|15|16|17|18|" _
& "19|20|21|22|23|24|" _
& "25|26|27|28|29|30|" _
& "31", "|")

With lst01
Me.ComboBox1.ColumnCount = 1
Me.ComboBox1.ColumnWidths = "25"
End With
For i = 0 To UBound(myArray1)
Me.ComboBox1.AddItem
Me.ComboBox1.List(i, 0) = myArray1(i)
Next i

End Sub
 
D

Doug Robbins - Word MVP

Use

Private Sub ComboBox1_DropButtonClick()

Dim myArray1 As Variant
myArray1 = Split("0|1|2|3|4|5|6|" _
& "7|8|9|10|11|12|" _
& "13|14|15|16|17|18|" _
& "19|20|21|22|23|24|" _
& "25|26|27|28|29|30|" _
& "31", "|")

With ComboBox1
.ColumnCount = 1
.ColumnWidths = "25"
.list = myArray1
End With

End Sub


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
D

Dylan

Hi Doug,

I've created a combo for months Jan, Feb, Mar, etc. But when I select a
month from the dropdown, it displays a number value e.g. mar = 3.

I've tried to lookup a solution to this in the post archives, but can't find
the solution.

Thanks Doug, for your help and support.

Ps. I posted this at the end of a message titled "Combo Box" in error, while
looking for a solution.

Dylan
 
D

Doug Robbins - Word MVP

Using the following code returns the month by its name for me

Private Sub ComboBox1_Change()
MsgBox ComboBox1.Value
End Sub

Private Sub ComboBox1_DropButtonClick()
Dim myArray1 As Variant
myArray1 = Split("January|February|March|April|May|June|July|" _
& "August|September|October|November|December|", "|")

With ComboBox1
.ColumnCount = 1
.ColumnWidths = "25"
.List = myArray1
End With
End Sub

I gather you probably have two comboboxes, one for the day and one for the
month. Are you sure that you are not getting them mixed up? It is a good
idea to give controls names that reflect their function, such as cmbDay and
cmbMonth. You are then far less likely to reference the wrong one in your
code.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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