Solved

VBA Delete DropDowns in cells

Posted on 2012-03-17
2
291 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

808 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