Setting all list boxes ListIndex = 0

fmascioni

New Member
Joined
Aug 11, 2008
Messages
46
Hello,

I'm trying to sett all list boxes to the first item with the following code:

For Each Lbox In Me.Controls
If TypeOf Lbox Is MSForms.ListBox Then Lbox.ListIndex = 0
Next Lbox

Getting the error "could not set listindex. Invalid property." Not sure why since Me.listboxname.ListIndex=0 works fine alone.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
My listbox is not empty however the first item is set to "". Ultimately what I'm trying to accomplish is make the default listbox item be empty upon initialization and upon the user hitting a "Clear All" button. Maybe there is an easier way?
 
Upvote 0
Yes, thats what I had originally but the individual I'm writing this for believes that his users may get confused thinking that if an item is showing it means it is selected (boxes are dimensioned to show only one row). If nothing is selected he wants the listbox to be blank.
 
Upvote 0

Forum statistics

Threads
1,214,528
Messages
6,120,065
Members
448,942
Latest member
sharmarick

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