J
JT
I have a macro that fills a form with 2 listboxes (single). The user selects
1 items from each listbox to match.....Works great......The listbox is
populated from the data source (hidden sheet) in the workbook.
However, and isn't there always a however, the users have requested that the
matching process allow multiple items to be selected from each listbox.
Sounds easy enough but it is more challenging than I thought.
Once the items are selected, they are moved to a "new" sheet and then
deleted from the data source sheet and the form is re-populated with the
first visible item being the index + 1. I'm having trouble getting the
individual indexes when someone selects more than one. I have tried using
the code below but I'm not able to get the individual indexes.
Any suggestions would be greatly appreciated. Thanks for the
help....FYI....this is one of the first times I have programmed listboxes so
I think that is probably part of the problem....
Sub Find_LB1_Item()
q = 1
For SR1 = 0 To LB1.ListCount - 1
If LB1.Selected(SR1) = True Then
ReDim Preserve SelRef1(1 To q)
ReDim Preserve SelRow1(1 To q)
ReDim Preserve TI1(1 To q)
SelRef1(q) = LB1.List(SR1, 0)
If Len(LB1.List(SR1, 4)) = 0 Then
SelAmt1 = 0
Else
SelAmt1 = SelAmt1 + LB1.List(SR1, 4)
End If
FoundLB1 = True
SelRow1(q) = LB1.List(SR1, 5)
TI1(q) = LB1.ListIndex ' this line
q = q + 1
End If
Next SR1
End Sub
1 items from each listbox to match.....Works great......The listbox is
populated from the data source (hidden sheet) in the workbook.
However, and isn't there always a however, the users have requested that the
matching process allow multiple items to be selected from each listbox.
Sounds easy enough but it is more challenging than I thought.
Once the items are selected, they are moved to a "new" sheet and then
deleted from the data source sheet and the form is re-populated with the
first visible item being the index + 1. I'm having trouble getting the
individual indexes when someone selects more than one. I have tried using
the code below but I'm not able to get the individual indexes.
Any suggestions would be greatly appreciated. Thanks for the
help....FYI....this is one of the first times I have programmed listboxes so
I think that is probably part of the problem....
Sub Find_LB1_Item()
q = 1
For SR1 = 0 To LB1.ListCount - 1
If LB1.Selected(SR1) = True Then
ReDim Preserve SelRef1(1 To q)
ReDim Preserve SelRow1(1 To q)
ReDim Preserve TI1(1 To q)
SelRef1(q) = LB1.List(SR1, 0)
If Len(LB1.List(SR1, 4)) = 0 Then
SelAmt1 = 0
Else
SelAmt1 = SelAmt1 + LB1.List(SR1, 4)
End If
FoundLB1 = True
SelRow1(q) = LB1.List(SR1, 5)
TI1(q) = LB1.ListIndex ' this line
q = q + 1
End If
Next SR1
End Sub