How Do I Get Data Out of A ListBox?

  • Thread starter Thread starter kenji4861
  • Start date Start date
K

kenji4861

I'm using a built in userform listbox with multiselect.

I named it lbx1

but I can't access it from the VB Editor.

I tried things like lbx1.value, lbx1.text
but lbx1 doesn't seem to exist in VB editor. I'm sure it's a simple
mistake. Someone please help me.
 
Ken,

Let's check some stuff.

When in the forms window (double-click this UserForm in the Project Explorer
pane), Do you see the listbox on the form?

When you select it, what name do you see in the properties window?

If you right-click your UserForm entry in the Project Explorer and do View
Code, then open the Object dropdown (upper left), is it listed there?
 
Right click on the list box and select Format Control. There is a place
there for input range, properties. etc.


Judy Freed
 
I would like to know how to get data OUT in the VB Editor.

The listbox is called lbx.
 
Is the listbox from the Forms toolbar or the Controls toolbar? You should be
using the one from the Controls toolbar. Once you do that, you can
right-click the control and choose View Code to access the control in VBA.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com (e-mail address removed)
 
I'm using the Form version. Any way to get the data out since I've had
many users use this. Thanks!
 
Is it set to allow multi selections:

Option Explicit
Sub testme02()

Dim myListBox As ListBox
Dim iCtr As Long

Set myListBox = ActiveSheet.ListBoxes("list box 1")

With myListBox
For iCtr = 1 To .ListCount
If .Selected(iCtr) Then
MsgBox .List(iCtr)
End If
Next iCtr
End With

End Sub

Or just one?

Option Explicit
Sub testme02a()

Dim myListBox As ListBox

Set myListBox = ActiveSheet.ListBoxes("list box 1")

With myListBox
MsgBox .List(.ListIndex)
End With

End Sub

(I'd put a "Ok" button (also from the forms toolbar) near the listbox and assign
it one of these macros.)
 
Back
Top