I am trying to populate an array with the items a user selected in a userform listbox. Below is my current code but it is not working, I keep getting a subscript out of range error on the following line "SelItems(k) = .List(i)"
I'm sure I am making a simple error but I am unable to figure it out and it is driving me crazy! Any help would be much appreciated.![]()
Dim lCount As Integer For i = 0 To ListBox1.ListCount - 1 'check if the row is selected and add to count If ListBox1.Selected(i) Then lCount = lCount + 1 Next i Dim SelItems As Variant ReDim SelItems(1 To lCount, 1 To 1) k = 1 With ListBox1 For i = 0 To .ListCount - 1 If .Selected(i) Then SelItems(k) = .List(i) k = k + 1 End If Next i End With
Bookmarks