Solved

VBA Delete DropDowns in cells

Posted on 2012-03-17
2
301 Views
Last Modified: 2012-06-27
Hi. I am using code like that shown below to add cells to a hundred cells in the top
row of a spreadsheet. What code would I use to delete all DropDowns in the top row of the sheet

Sub DD()

With ActiveSheet.DropDowns.Add(142.5, 38.25, 108.75, 24)
    .Top = Range("C1").Top
    .Left = Range("C1").Left
    .Height = Range("C1").Height
    .Width = Range("C1").Width
End With


End Sub
0
Comment
Question by:murbro
2 Comments
 
LVL 42

Accepted Solution

by:
dlmille earned 500 total points
ID: 37733404
Attached are two subs.  One creates dropdowns from A1:G5, so for 5 rows we have drop downs.  The second sub deletes only those dropdowns on the first row (again, looking from A:G, but you can change the range).

It does this by checking the rows .Top and .Left and compares this with the dropdowns that are parked in the same location's .Top and .Left.

Sub DD()
Dim r As Range
Dim rng As Range

    Set rng = Range("A1:G5")
    For Each r In rng
        With ActiveSheet.DropDowns.Add(142.5, 38.25, 108.75, 24)
            .Top = r.Top
            .Left = r.Left
            .Height = r.Height
            .Width = r.Width
        End With
    Next r

End Sub

Sub deleteDropDownsFirstRow()
Dim wks As Worksheet
Dim r As Range
Dim rng As Range
Dim sObj As Object

    Set wks = ActiveSheet
    Set rng = wks.Range("A1:G1")
    
    For Each sObj In wks.Shapes
        If sObj.FormControlType = xlDropDown Then 'Found a drop down
            'check if on row 1 using .Top & .Left of each cell being tested
            For Each r In rng
                If sObj.Top = r.Top And sObj.Left = r.Left Then
                    sObj.Delete
                    Exit For
                End If
            Next r
        End If
        
    Next sObj
End Sub

Open in new window


See attached demonstration workbook.

Cheers,

Dave
delDropDownsRow1-r1.xls
0
 

Author Closing Comment

by:murbro
ID: 37735051
Thanks very much
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question