How to load the contents of a ListBox or ComboBox directly into an array

Article contributed by Ibby

One way of loading the contents of a ListBox into an array is to loop through the elements in the ListBox and assign them to the elements in the array, one by one.

You can also do this directly. As the Help file points out, you can fill a ListBox with the contents of an array using:

ListBox1.List() = myArray

You can also do the reverse:

myArray = ListBox1.List()

However, when you do this, you need to be aware that the result is a 2 dimensional array with the data from the ListBox stored in the first dimension. Below is a code example:

Dim myArray As Variant
Dim i As Long

myArray = ListBox1.List()

For i = 0 To UBound(myArray)
    MsgBox myArray(i, 0)
Next i

See also:
Displaying a message box after using ListBoxName.List() in a double-click event disables all other UserForm controls