Listbox data

R

ranswrt

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
 
J

Joel

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)
 
R

ranswrt

I changed it to 'a(cnt, j) = ListBox1.List(j)' , but the data in 'a' isn't
what I wanted. I am trying to get 'a' to get the data on a row that has been
selected on the listbox. There is 7 columns and i need data from each column
in 'a'. What am I doing wrong?
Thanks
 
R

ranswrt

I tried that and that didn't work either. I am trying to get the values of
the row or rows that are selected in a listbox. I want to put these values
in a worksheet. I put in the 'msgbox' to see what value were being assigned
to 'a'. There are 7 columns in the listbox that I need to values from also.
 
J

Joel

a(cnt, j) = ListBox1.listindex

ranswrt said:
I tried that and that didn't work either. I am trying to get the values of
the row or rows that are selected in a listbox. I want to put these values
in a worksheet. I put in the 'msgbox' to see what value were being assigned
to 'a'. There are 7 columns in the listbox that I need to values from also.
 
R

ranswrt

I tried 'a(cnt, j) = ListBox1.listindex' but that just assigned the row
number to 'a'. I am trying to get the values from each column is the row or
row's that was selected in the user for.
 
J

Joel

a(cnt, j) = ListBox1.List(i, j)

ranswrt said:
I tried 'a(cnt, j) = ListBox1.listindex' but that just assigned the row
number to 'a'. I am trying to get the values from each column is the row or
row's that was selected in the user for.
 

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