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.
 

Some videos you may like

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.

fmascioni

New Member
Joined
Aug 11, 2008
Messages
46

ADVERTISEMENT

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?
 

fmascioni

New Member
Joined
Aug 11, 2008
Messages
46

ADVERTISEMENT

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.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,564
Messages
5,596,875
Members
414,106
Latest member
Tigretto

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