VBA: How to clear listbox items?

dbmathis

Well-known Member
Joined
Sep 22, 2002
Messages
1,064
Hi all,

I have a simple question. How does one clear a listbox with VBA?

Thanks
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
What do you mean by clear?

Clear the contents?
Code:
Listbox1.Clear
Clear the selection(s)?
Code:
Listbox1.ListIndex = -1
 
Upvote 0
Hmmm. It was actually filled with an array. I tried .clear before I posted and it didn't work? Now it does? Must have been a typo.

Thanks for the prompt response.
 
Upvote 0
If you use the .clear method it leaves empty rows at the end of the list. If i fill it up with a smaller list than it will leave empty entries that i can select at the bottom of the list. Does it function like an array and i need to redim it?
 
Upvote 0
Important response on different method to clear based on how it was loaded. I was getting an "unspecified error" when using ListBox1.Clear because it was filled with RowSource. Changed to ListBox1.RowSource = "" and it works great. Thanks
 
Upvote 0
Doing what Mustang0710 did in post #6 is what I needed, however, is there a way to retain the header rows in the listbox after the other rows have been cleared?
 
Upvote 0

Forum statistics

Threads
1,223,693
Messages
6,173,868
Members
452,536
Latest member
Chiz511

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