How to clear all item from a combo box?

3

39N95W

I know this is simple, but I just can't remember the syntax. How do I clear
all the items from a combo box? Isn't there a one-step process for doing
this?

All help appreciated. TIA.

-gk-
 
C

Chip Pearson

Use the Clear method of the ComboBox control. E.g.,

Userform1.ComboBox1.Clear



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
T

Tom Ogilvy

If bound to a worksheet using rowsource for example, just set the rowsource
to a null string.

If added using additem, then use removeitem.

or
Private Sub CommandButton2_Click()
Dim Emp()
ReDim Emp(0 To 0)
Me.ComboBox1.List = Emp
Me.ComboBox1.RemoveItem 0
End Sub
 
T

Tom Ogilvy

Whoops -
As Chip said, clear would be a better approach for controls not bound to the
spread sheet.
 
T

Tim Coddington

I am having a similar problem. But what if you have a '.change'
routine that should perform the .clear function? The .clear seems
to fire the .change and you get .clear twice without re-loading the
combobox, and you get a crash. What is the best way to work
around this?
 
S

Stan Scott

The easiest way to do this, I think, is with a global variable. For
example, you could do something like this:

Dim stopEvents as boolean

Private Sub object1_change()
stopEvents = true
do the clear
stopEvents = false
end sub

Private Sub object2_change()
if not(stopEvents) then
do something
end if
end sub

Stan Scott
New York City
 
3

39N95W

Chip Pearson said:
Use the Clear method of the ComboBox control. E.g.,

Userform1.ComboBox1.Clear

Doh! Let me just say that, swear on my daddy's grave, that I tried typing
in the form object, pressing "." after the combobox and then scrolling
through the list of options. For what ever reason, I just wasn't seeing it.

Thanks again!

-gk-
 
K

keepITcool

nope.

For a combobox and listbox (UNBOUND) setting the list to an empty array
is faster than using the clear method.

with 100'000 items takes 2.2secs vs 0.06 sec





keepITcool

< email : keepitcool chello nl (with @ and .) >
< homepage: http://members.chello.nl/keepitcool >
 
Top