Solved

VBA Delete DropDowns in cells

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
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 will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now