I have a listbox on a form set as MultiSelect and I want to put the rows that were selected in an array. Consider this code:
I want to put the row number of the check box selected from the listbox into an array. For example, if I select row 2 from the listbox, the number 2 gets put into the array cell; if row 10 gets selected, then the number 10 gets put into the array cell. I can select multiple rows from the listbox and have these row numbers in the array (2, 10, 15, 19, etc). I created a dynamic array because the listbox items can be over several hundred and I only want to display the row numbers in the array.
The problem is that I can't display the array elements. Are these values getting into the array or are they being overwritten?
Code:
Dim chkBoxArr() as long
Dim icount, j as integer
For j = 1 To Userform1.Listbox1.ListCount - 1
If UserForm1.ListBox1.Selected(j) Then
chkBoxArr(icount) = j
icount = icount + 1
End If
Next j
ReDim Preserve chkBoxArr(j)
For icount = LBound(chkBoxArr) To UBound(chkBoxArr)
If chkBoxArr(icount) <> 0 Then
MsgBox chkBoxArr(icount)
Next icount
I want to put the row number of the check box selected from the listbox into an array. For example, if I select row 2 from the listbox, the number 2 gets put into the array cell; if row 10 gets selected, then the number 10 gets put into the array cell. I can select multiple rows from the listbox and have these row numbers in the array (2, 10, 15, 19, etc). I created a dynamic array because the listbox items can be over several hundred and I only want to display the row numbers in the array.
The problem is that I can't display the array elements. Are these values getting into the array or are they being overwritten?