I have a Form called FormInput which I have populated with ListBoxes which the users have to select. I am looking for suitable code to loop through all of these listboxes and return the values of the boxes.
I have tried this as is suggested in my VBA book but it doesn't work.
Dim a As Integer
a = 38
For Each ListBox In Me.Controls
For i = 0 To ListBox.ListCount - 1
If ListBox.Selected(i) Then
Cells(a, 1).Value = ListBox.List(i, 0)
Cells(a, 2).Value = ListBox.List(i, 1)
a = a + 1
End If
Next i
Next
The thing that I am stuck with is how to loop through the ListBoxes. Is the ref. to Me.Controls maybe not the right one ?
Can anyone help please,
Richard
I have tried this as is suggested in my VBA book but it doesn't work.
Dim a As Integer
a = 38
For Each ListBox In Me.Controls
For i = 0 To ListBox.ListCount - 1
If ListBox.Selected(i) Then
Cells(a, 1).Value = ListBox.List(i, 0)
Cells(a, 2).Value = ListBox.List(i, 1)
a = a + 1
End If
Next i
Next
The thing that I am stuck with is how to loop through the ListBoxes. Is the ref. to Me.Controls maybe not the right one ?
Can anyone help please,
Richard