List boxes

CH

New Member
Joined
Apr 8, 2002
Messages
1
Is it possible to create a list box that allows you to make multiple selections and can return information associated with those selected items to a table or something? I can get it to work when the Selection Type is 'single', but nothing seems to happen when it's changed to 'multi' or 'extend'.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
I had the same problem. The problem that I came across was when you select multi in your properties, then theres no value. I wasnt able to get help on this question, so I reconfigured how I let the user select a choice. Unfortanatly I had to keep the property to single so there was a value! I wonder how else this could of been done?
 
Upvote 0
Do you mean that it won't let you select more than one item? Or after they're selected you can't do something with the selections? Is the listbox on a form?

Dave
 
Upvote 0
The VBE help says:
"When the MultiSelect property is set to Extended or Simple, you must use the list box's Selected property to determine the selected items. Also, the Value property of the control is always Null.

The ListIndex property returns the index of the row with the keyboard focus."

Which leads me to believe that you have to use the listindex property rather than the value property to return anything.
 
Upvote 0
Okay, I was wrong. What you have to do is use the Selected property to find which items in the list box were selected (the selected property returns true or false) and then use the list property of the list box to return the value. I wrote this code to print the values from a list box (lstListBox) with 6 values on a label. The multiselect property of the list box is set to extend. This code runs off a command button.

Private Sub cmdPrintListSelection_Click()
Dim n As Integer
Dim strItem As String

For n = 0 To 5
If lstListBox.Selected(n) = True Then
strItem = strItem & " " & lstListBox.List(n)
lblPrintList.Caption = strItem
End If
Next n
End Sub

It will print all of the selected items on the label.

I hope that helps.

Dave
 
Upvote 0

Forum statistics

Threads
1,213,528
Messages
6,114,154
Members
448,553
Latest member
slaytonpa

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top