+ Reply to Thread
Results 1 to 4 of 4

Using VBA to delete a button with a row

Hybrid View

  1. #1
    Registered User
    Join Date
    08-27-2009
    Location
    Sacramento, CA
    MS-Off Ver
    Excel 2003
    Posts
    2

    Using VBA to delete a button with a row

    I have a spreadsheet that has multiple buttons in each row. One of these buttons is labled "Delete" and all the macro does is delete the row.

    The problem with this is that the buttons do NOT get deleted. The become smaller and kindof squished between two rows.

    Is there a code I can use to delete these buttons along with the row?
    Since there are so many buttons that do the same thing (based on what row the button is in) naming the button would not work.

    Thank you in advance for any help

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Using VBA to delete a button with a row

    You would need to loop through all the buttons and check there TopLeftCell property. If it matches the current row the delete the control
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    08-27-2009
    Location
    Sacramento, CA
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Using VBA to delete a button with a row

    I use the TopLeftCell property to select the cell under the button, but that is as much as I know. Can I get an example of how to use it in the loop as discribed and then delete the control?

    Thank you

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Using VBA to delete a button with a row

    Assumes the buttons are assigned to PressMe macro

    Sub PressMe()
    
        Dim shpTemp As Shape
        Dim lngRow As Long
        Dim lngIndex As Long
        
        lngRow = ActiveSheet.Shapes(Application.Caller).TopLeftCell.Row
        For lngIndex = ActiveSheet.Shapes.Count To 1 Step -1
            If ActiveSheet.Shapes(lngIndex).TopLeftCell.Row = lngRow Then
                ActiveSheet.Shapes(lngIndex).Delete
            End If
        Next
        ActiveSheet.Rows(lngRow).Delete
        
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1