View Full Version : Removing all values in a list box.
lienlee
06-01-2010, 11:32 AM
How would i go about creating a vba code to delete all the values in my listbox.
i added my values by using the listboxname.additem "sentence"
but i want all values to be gone when i do something else. like click a button to another location
mdmackillop
06-01-2010, 12:55 PM
Listbox1.Clear
lienlee
06-02-2010, 06:13 AM
Listbox1.Clear
.Clear doesnt seem to exist with the vba im runnig.
CreganTur
06-02-2010, 07:03 AM
You need to replace Listbox1 with the name of the listbox object you want to work with. Clear is a valid method of listbox objects.
krishnak
06-03-2010, 11:16 AM
ListBox1.Clear does not work. In fact Clear is not a valid method as it does not show in the intellisense display. We get an error message as well.
I use the following code which works well in my macros.
Do
ListBox1.RemoveItem (0)
Loop While (ListBox1.ItemData(0) <> "")
-Krishna
CreganTur
06-03-2010, 12:04 PM
Clear must be new to 2007- that's the version I'm using.
lienlee
06-04-2010, 08:36 AM
This way also works. just tested.
dim j as integer
For j = 0 To Listbox1.ListCount - 1
Listbox1.RemoveItem (0)
Next
Thanks everyone.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.