Thread: Listbox data
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default Listbox data

The data in array a(1,0) is empty. I think you need the following change

from
a(cnt, j) = ListBox1.List()
to
a(cnt, j) = ListBox1.List(j)

"ranswrt" wrote:

I have the following code:

Private Sub ListBox1_Change()
Dim i As Integer
Dim cnt As Integer
Dim num As Integer
Dim j As Integer

num = ListBox1.ListCount
ReDim a(num, 7)
cnt = 0
For i = 0 To num - 1
If ListBox1.Selected(i) = True Then
cnt = cnt + 1
For j = 0 To 6
a(cnt, j) = ListBox1.List()
MsgBox ("a(" & cnt & "," & j & ")= " & a(cnt, j))
Next

End If
Next


End Sub

I am trying to get the data from the selected items on a listbox in a
userform. The list box has 7 columns. When i select an item in the listbox,
I get a 'type mismatch' error. How do I collect the data from a selected
rows in a listbox?
Thanks