Clearing list from all form commandboxes

J

josh ashcraft

attn: Tom Oglivy or anyone else who may be able to help...

I need help Clearing the list from all form commandboxes
on my worksheet, the code I had earlier didn't seem to
work correctly, or I was using it wrong, could someone
please help me with this?
Thanks in advance,
Josh
 
V

Vasant Nanavati

Hi Josh:

What is a "commandbox"?

If you mean ComboBoxes:

Sheet1.ComboBox1.Clear
Sheet1.ComboBox2.Clear

etc.

You cannot clear ComboBoxes in this fashion if they are populated via a
RowSource.

Regards,

Vasant.
 
T

Tom Ogilvy

Some more:

These all worked for comboboxes (dropdowns) from the Forms Toolbar:

Sub ClearListFill()
Dim drp As DropDown
For Each drp In ActiveSheet.DropDowns
drp.ListFillRange = ""
Next
End Sub

Sub Populate()
Dim drp As DropDown
For Each drp In ActiveSheet.DropDowns
drp.RemoveAllItems
drp.AddItem "1st"
drp.AddItem "2nd"
drp.AddItem "3rd"
drp.AddItem "4th"
drp.AddItem "5th"
Next

End Sub
Sub ClearDropDown()
'clear list set with listfillrange or additem
Dim drp As DropDown
For Each drp In ActiveSheet.DropDowns
drp.RemoveAllItems
Next

End Sub

Sub SetListFill()
Dim drp As DropDown
For Each drp In ActiveSheet.DropDowns
drp.ListFillRange = ActiveSheet. _
Range("A1:A10").Address(external:=True)
Next

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top