Data from multiple listbox(s) to one array

Hello

looking for a quick way to loop through multiple listboxes contained on one userform and take all the data from each and add it to an array.

Dim cCont As Control

For Each cCont In Me.Controls
If TypeName(cCont) = "ListBox" Then
'how do I loop through each list box and dump the data
End If
Next cCont

I am new to this...

Thanks




Answer this question

Data from multiple listbox(s) to one array

  • Mathieu DESPRIEE

    Hi,

    Yip you should be able to do something like this...

    For Each cCont In Me.Controls
    If TypeName(cCont) = "ListBox" Then

    Dim lstBox as ListBox

    Set lstBox = cCont

    Dim iCount As Integer
    For iCount = 0 To Me.lstBox.ListCount - 1
    MsgBox Me.lstBox.List(iCount, 0)
    Next

    End If
    Next cCont



  • bongoMaster

    Thanks for your answer...

    I have multiple listbox's, about 25 or so. I don't want to duplicate the above code 25 times. Is there a way do make me.listbox1..... a variable


  • John Cargill

    Here is an example of looping over the items in listbox

    Me.ListBox1.AddItem ("Hello")
    Me.ListBox1.AddItem ("World")

    Dim iCount As Integer
    For iCount = 0 To Me.ListBox1.ListCount - 1
    MsgBox Me.ListBox1.List(iCount, 0)
    Next



  • Data from multiple listbox(s) to one array