NdNoviceHlp
Well-known Member
- Joined
- Nov 9, 2002
- Messages
- 3,734
I've made a trial to demonstrate. Add data to A1:B10 and a Userform with a Listbox. The following code is supposed to load the listbox with A1:A10 (and "TEST) on initialize and then when "TEST" is selected the Listbox clears and loads B1:10. Simple enough, but how to clear the phantom selection in the listbox (it's coded to = -1)? When "TEST" is selected, the Listbox updates but keeps the same listitem selected in the new list (unless the first listitem is selected and then it works as expected?). A sort of remedy is to use Application.Wait. It's probably something simple...maybe a listbox setting thing? Anyways, any help is always appreciated. Dave
ps. XL03 code
Code:
Private Sub UserForm_Initialize()
UserForm1.ListBox1.ListStyle = fmListStyleOption
UserForm1.ListBox1.MultiSelect = fmMultiSelectSingle
For Cnt1 = 1 To 10
UserForm1.ListBox1.AddItem "TEST"
UserForm1.ListBox1.AddItem Sheets("Sheet1").Range("A" & Cnt1).Value
Next Cnt1
End Sub
Private Sub ListBox1_Click()
If UserForm1.ListBox1.Value = "TEST" Then
UserForm1.ListBox1.ListIndex = -1
'Application.Wait (Now + TimeValue("0:00:01"))
UserForm1.ListBox1.Clear
For Cnt2 = 1 To 10
UserForm1.ListBox1.AddItem Sheets("Sheet1").Range("B" & Cnt2).Value
Next Cnt2
End If
End Sub
ps. XL03 code