listbox

mikeymay

Well-known Member
Joined
Jan 17, 2006
Messages
1,600
Office Version
  1. 365
Platform
  1. Windows
I am trying to loop through a number of items that are in a listbox and to establish if they have been selected or not but just can't seem to get the ListIndex and ListCount right... :(

Also, how do you specify that a listbox can have multiple items selected?


Thanks
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
You change the multiselect property of the Listbox to fmMultiSelectMulti or fmMultiSelectExtended, this allows you to select multiple items
 
Last edited:
Upvote 0
Basic syntax is:
Code:
for n = 1 to listbox.listcount
if listbox.selected(n - 1) then
' do something
end if
next n
 
Upvote 0
That's got it!

What does the Extended option allow you to do?


Thanks
 
Upvote 0
Thanks RoryA

Have to knock off now but I will check this out when working on it next.
 
Upvote 0
BTW, Multi means you have to click each item individually to select/deselect it. Extended works like Win Explorer - you can Shift+click to select a block of items, then Ctrl+click to add individual ones.
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,044
Members
449,063
Latest member
ak94

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