PDA

View Full Version : Is item selected in multi-select listbox?



clhare
10-25-2011, 10:17 AM
I have a userform that has several textboxes and also a multi-select listbox with about 30 items in it.

I need to update the userform so that if a particular item in the multi-select list box is selected (regardless of how many items are selected), one of the textboxes on the form which is initially disabled becomes enabled.

I have absolutely no idea how to do this. Can someone please help me?

Cheryl

gmaxey
10-25-2011, 12:20 PM
Listbox list members are index starting with 0. So "B" is index "1." If "B" is selected then the textbox is enabled.


Option Explicit
Private Sub ListBox1_Change()
If Me.ListBox1.Selected(1) Then
Me.TextBox1.Enabled = True
Else
Me.TextBox1.Enabled = False
End If
End Sub
Private Sub UserForm_Initialize()
With Me.ListBox1
.AddItem "A"
.AddItem "B"
.AddItem "C"
End With
Me.TextBox1.Enabled = False
End Sub

clhare
10-26-2011, 09:12 AM
Still won't work for me. I originally populated the list box with an array and the code didn't work for that, then I changed it to populate the list box as you show, and it still didn't work.

clhare
10-26-2011, 11:41 AM
It's working now-- I think I had missed switching "Click" to "Change". Thanks so much for your help!