listbox

mikeymay

Well-known Member
Joined
Jan 17, 2006
Messages
1,564
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

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Momentman

Well-known Member
Joined
Jan 11, 2012
Messages
4,142
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
You change the multiselect property of the Listbox to fmMultiSelectMulti or fmMultiSelectExtended, this allows you to select multiple items
 
Last edited:
Upvote 0

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
40,380
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
Basic syntax is:
Code:
for n = 1 to listbox.listcount
if listbox.selected(n - 1) then
' do something
end if
next n
 
Upvote 0

mikeymay

Well-known Member
Joined
Jan 17, 2006
Messages
1,564
Office Version
  1. 365
Platform
  1. Windows
That's got it!

What does the Extended option allow you to do?


Thanks
 
Upvote 0

mikeymay

Well-known Member
Joined
Jan 17, 2006
Messages
1,564
Office Version
  1. 365
Platform
  1. Windows
Thanks RoryA

Have to knock off now but I will check this out when working on it next.
 
Upvote 0

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
40,380
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
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,191,191
Messages
5,985,211
Members
439,947
Latest member
fabiannic

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
Top