Your technology certification is waiting. Enroll in Cloud Class ®
Dim j As Integer
Dim i As Integer
Redim b(1 To ListBox1.ListCount, 1 To 1)
' to add listbox to array
For i = 0 To ListBox1.ListCount
j = j + 1: b(j, 1) = ListBox1.List(i, 1)
' to add array to listbox
For i = 1 To UBound(b, 1)
If Not IsEmpty(b(i, 1)) Then ListBox1.AddItem b(i, 1)
Open in new window
Dim vntData As Variant
'listbox to array:
vntData = ListBox1.List
'array to listbox:
ListBox1.List = vntData
Dim objList As Object
' you can use objList in place of ListBox1.
'You may declare the variable in a module to use it globally.
Public objList as Object
'To fill an array: Use preserve keyword to keep previous items.
' This is a string variable and not to be manipulated as List Box.
Dim lb() As String
Dim i, j As Integer
j = -1
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
j = j + 1
ReDim Preserve lb(j)
lb(j) = ListBox1.List(i)
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.