bensdb
02-12-2014, 09:06 AM
Hi I have a multicolumn multiselect listbox. I would like to transfer the selected items in this listbox to an array, which I will then use to populate another listbox.
It keeps coming up with subscript out of range and i cant figure out why?!?!?!?
Doing my head in. Please help....NB this is the first time ive used Redim Preserve.
Sub listboxlist()
i = 0
j = 0
Z = 0
Dim ar_temp()
For i = 0 To SortReg.Controls("Listbox2").ListCount - 1
If SortReg.Controls("Listbox2").Selected(i) = True Then
Z = Z + 1
ReDim Preserve ar_temp(0 To Z - 1, 0 To 7)
For j = 0 To 7
ar_temp(Z - 1, j) = SortReg.Controls("Listbox2").List(i, j)
Next
End If
Next
SortReg.Controls("Listbox8").List = ar_temp
End Sub
It keeps coming up with subscript out of range and i cant figure out why?!?!?!?
Doing my head in. Please help....NB this is the first time ive used Redim Preserve.
Sub listboxlist()
i = 0
j = 0
Z = 0
Dim ar_temp()
For i = 0 To SortReg.Controls("Listbox2").ListCount - 1
If SortReg.Controls("Listbox2").Selected(i) = True Then
Z = Z + 1
ReDim Preserve ar_temp(0 To Z - 1, 0 To 7)
For j = 0 To 7
ar_temp(Z - 1, j) = SortReg.Controls("Listbox2").List(i, j)
Next
End If
Next
SortReg.Controls("Listbox8").List = ar_temp
End Sub