Listbox text property not working correctly

S

Shawn

I am using Excel 2002. I have created a form with 4 listboxes all
populated with For..Next loops during the Userform Initialize
procedure.

I then select an item in each listbox using listbox1.listindex = xx.

I then try to access the selected items using listbox.text and display
the results in a message box.

I only receive the correct answer for two listboxes. The other two
listboxes (not always the same two listboxes) appear to be empty. (See
example code below.)

Private Sub UserForm_Initialize()
Dim x As Integer

For x = 1 To 50
With ListBox1
.AddItem "Number " & x
End With
Next x
For x = 1 To 50
With ListBox2
.AddItem "Number " & x
End With
Next x
For x = 1 To 50
With ListBox3
.AddItem "Number " & x
End With
Next x
For x = 1 To 50
With ListBox4
.AddItem "Number " & x
End With
Next x

With UserForm1
.ListBox1.ListIndex = 30
.ListBox2.ListIndex = 31
.ListBox3.ListIndex = 32
.ListBox4.ListIndex = 33
End With

MsgBox "Box 1 = " & ListBox1.Text & Chr(13) & "Box 2 = " &
ListBox2.Text & Chr(13)
MsgBox "Box 3 = " & ListBox3.Text & Chr(13) & "Box 4 = " &
ListBox4.Text & Chr(13)

End Sub

Any help would be greatly appreciated.
 
R

Robin Hammond

Try using the value or list commands instead.

msgbox(lst1.list(lst1.listindex))

appears to be the most reliable way to get a return value even if it is long
winded.

Robin Hammond
www.enhanceddatasystems.com
Check out our XspandXL add-in
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top