Deleting all dropdowns...

  • Thread starter Thread starter Chip
  • Start date Start date
C

Chip

I want to be able to delete (using VBA) all the dropdowns on a
worksheet. When I record the act of deleting a dropdown I get:

ActiveSheet.Shapes("Drop Down 24").Select
Selection.Delete

How to I do it for more than Drop Down 24?
 
For all Shapes on your worksheet you can use this

ActiveSheet.DrawingObjects.Delete
 
Here is some code that Dave Peterson and I came up with a while back. It
deletes the shapes, but not any code behind it

Sub testme()
Dim shp As Shape
Dim testStr As String
Dim OkToDelete As Boolean

For Each shp In ActiveSheet.Shapes
OkToDelete = True

testStr = ""
On Error Resume Next
testStr = shp.TopLeftCell.Address
On Error GoTo 0

If shp.Type = msoFormControl Then
If shp.FormControlType = xlDropDown Then
If testStr = "" Then
'keep it
OkToDelete = False
End If
End If
End If

If OkToDelete Then
shp.Delete
End If

Next shp

End Sub

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Just to add -
You only need to be this elaborate if you have Autofilter dropdowns on your
worksheet - I would think this would be unusual if you have forms control
dropdowns on the sheet. If you won't, then

Activesheet.Dropdowns.Delete

is sufficient.
 
Just to add -
You only need to be this elaborate if you have Autofilter dropdowns on your
worksheet -

or Data Validation.

And if you do, and you delete them, you can't get them back.
 
In Excel 2003, I couldn't reproduce the problem with a Data Validation
dropdown whether it was visible or not at the time the command was issued.
 

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

Back
Top