Reputation: 225
Hi I'm newbie in vba excel, but i didn't find yet what i'm looking for in google.
I want a list like this in my combo box
BUS B
APPLE A
SUGAR S
JELLY J
I do like this in the past
Dim listEntries(3, 2) As Variant
listEntries(0, 0) = "A"
listEntries(0, 1) = "Apple"
listEntries(1, 0) = "S"
listEntries(1, 1) = "Sugar"
listEntries(2, 0) = "J"
listEntries(2, 1) = "Jelly"
Me.ComboBox1.List = listEntries
but now days the data become so many. I want the list is coming from another sheet list. I found this in Google. but it is still not works
Private Sub UserForm_Initialize()
Dim cItem As Range
Dim ws As Worksheet
Set ws = Worksheets("LookupLists")
For Each cItem In ws.Range("ItemList")
With Me.cboItem
.AddItem cItem.Value
.List(.ListCount - 1, 1) = cItem.Offset(0, 1).Value
End With
Next cItem
End Sub
Is there any missed in my code or is there another way to get the multiple value from another sheet ?
Upvotes: 1
Views: 2188
Reputation: 34035
You don't need to loop if you just want to put a range in the list:
Private Sub UserForm_Initialize()
Me.cboItem.List = Worksheets("LookupLists").Range("ItemList").Resize(, 2).Value
End Sub
Upvotes: 1