Max,
Try the code below in the userform's codemodule. Assumes that you have a 2 column listbox named
Listbox1 on your userform, with its multiselect property set to multi.
HTH,
Bernie
MS Excel MVP
Option Explicit
Private Sub UserForm_Initialize()
'Populate the listbox with some values
Dim i As Integer
Dim j As Integer
Dim myArr(1 To 10, 1 To 2) As Integer
For i = 1 To 10
For j = 1 To 2
myArr(i, j) = i * 2 + IIf(j = 1, 100, 1)
Next j
Next i
Me.ListBox1.List = myArr
End Sub
'Get the selection of the listbox
Private Sub CommandButton1_Click()
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim mySel(1 To 10, 1 To 2) As Integer
i = 1
With Me.ListBox1
For k = 0 To .ListCount - 1
If .Selected(k) = True Then
mySel(i, 1) = Me.ListBox1.List(k, 0)
mySel(i, 2) = Me.ListBox1.List(k, 1)
i = i + 1
End If
Next k
End With
For j = 1 To i - 1
MsgBox "Selected " & mySel(j, 1) & ", " & mySel(j, 2)
Next j
End Sub
"Max" <(E-Mail Removed)> wrote in message
news:45FC1BDC-8E29-4B68-9BD4-(E-Mail Removed)...
> Help this noob out...
>
> I want to place data in an array in a listbox. Then I want a user to select
> one or multiple values within that text box.
>
> 1) How do I initialize the listbox?
> 2) How do populate the listbox with the array contents?
> 3) How do I store the user selection into another array?
>
> --
> Thanks!
> Max
|