Hi There,
Is it possible to add multiple listbox items into a single array? The code below works for a single Listbox1, how do I add a second Listbox to the end of the first array, e.g. Listbox1
Is it possible to add multiple listbox items into a single array? The code below works for a single Listbox1, how do I add a second Listbox to the end of the first array, e.g. Listbox1
Code:
Private Sub CmdOk_Click()
Dim myArray() As String
Dim Count As Integer, i As Integer, j As Integer
Count = 0
For i = 0 To ListBox1.ListCount - 1
'check if the row is selected and add to count
If ListBox1.Selected(i) Then Count = Count + 1
Next i
'based on the above count declare the array
ReDim myArray(Count)
j = 0
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
'if selected then store the item from the
'first column in the array. change 1 to the
'respective column number
myArray(j) = ListBox1.List(i, 0)
j = j + 1
End If
Next i
'Check values stored in array
For i = 0 To Count - 1
MsgBox myArray(i)
Next i
End Sub