View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Shawn[_2_] Shawn[_2_] is offline
external usenet poster
 
Posts: 1
Default Listbox text property not working correctly

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.



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/