+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 18

Thread: Delete Form Control Buttons in a range on worksheet

  1. #1
    Registered User
    Join Date
    12-26-2011
    Location
    Bangalore,India
    MS-Off Ver
    Excel 2007
    Posts
    27

    Delete Form Control Buttons in a range on worksheet

    I am trying to delete the form the control buttons in a specified range in a sheet. But the code i have written is returning error:

    Run Time Error '438':
    Object Doesn't support this property or method.

    the code i have written is.
    Private Sub ComboBox1_Change()
    
    Dim shp As Shape
    
    If ComboBox1.Value = "IONE" Then
        Application.Goto Reference:="ionee"
        Selection.Copy
        Range("A6").Select
        ActiveSheet.Paste
    ElseIf ComboBox1.Value = "PLS" Then
    
    Else
    'MsgBox("Please select an option from drop down..!", vbOKOnly, "Error") = vbOK
    Range("A6:Y54").Select
    Selection.ClearContents
     'Range("D8:D14").Select
        With Selection.Validation
            .Delete
            .Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator _
            :=xlBetween
            .IgnoreBlank = True
            .InCellDropdown = True
            .InputTitle = ""
            .ErrorTitle = ""
            .InputMessage = ""
            .ErrorMessage = ""
            .ShowInput = True
            .ShowError = True
        End With
        DBC
       End If
    
    End Sub
    Public Sub DBC()
    Dim i As Integer
    For i = ActiveSheet.Range("A6:Y54").Shapes.Count To 1 Step -1
    If ActiveSheet.Range("A6:Y54").Shapes(i).Type = msoFormControl Then
    If ActiveSheet.Range("A6:Y54").Shapes(i).FormControlType = xlButtonControl Then
    ActiveSheet.Range("A6:Y54").Shapes(i).Delete
    End If
    End If
    Next i
    End Sub
    Any help will be appreciated. Thanks.!!
    Last edited by abhiD; 01-20-2012 at 04:33 AM.

  2. #2
    Forum Guru mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    2,998

    Re: Delete Form Control Buttons in a range on worksheet

    I believe this is the offending line.
    .Shapes is a proprety of a Sheet object, not a Range object. Perhaps
    For i = ActiveSheet.Range("A6:Y54").Shapes.Count To 1 Step -1
    Perhaps,
    Dim ClearRange As Range
    
    Set ClearRange = ActiveSheet.Range("A6:Y54")
    
    With ClearRange.Parent
        For i = 1 to .Shapes.Count
            With .Shapes(i)
                If Not Application.Intersect(Range(.TopLeftCell, .BottomRightCell), ClearRange) Is Nothing Then
                    If .Type = msoFormControl Then
                        If .FormControlType = xlButtonControl Then
                            .Delete
                        End IF
                    End If
                End If
            End With
        Next i
    End With
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Registered User
    Join Date
    12-26-2011
    Location
    Bangalore,India
    MS-Off Ver
    Excel 2007
    Posts
    27

    Re: Delete Form Control Buttons in a range on worksheet

    thanks mike for the reply. but its not working its putting up run time error this time, the index into the specified collection is out of bounds.

    In brief what i am trying to do is, i have a combo box made and on selecting an option from the drop down a named range is to appear at A6, now that range has some form control buttons assigned with code to insert rows at specific places if required. Now, when a user selects the other option or he clears the combo box then the range A6:Y54 is to be cleared of everything, including the buttons. but in the code

    Public Sub DBC()
    Dim i As Integer
    'For i = ActiveSheet.Shapes.Count To 1 Step -1
    'If ActiveSheet.Shapes(i).Type = msoFormControl Then
    'If ActiveSheet.Shapes(i).FormControlType = xlButtonControl Then
    'ActiveSheet.Shapes(i).Delete
    'End If
    'End If
    'Next i
    End Sub
    the entire sheet is getting cleared of the boxes, which is not i want thats why i tried modifying it, but it is showing error.

    M Stuck..

  4. #4
    Valued Forum Contributor OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,647

    Re: Delete Form Control Buttons in a range on worksheet

    Hi,
    I suspect that with Mike's code you may need to loop backwards

    Dim ClearRange As Range
    
    Set ClearRange = ActiveSheet.Range("A6:Y54")
    
    With ClearRange.Parent
        For i = .Shapes.Count to 1 step -1
            With .Shapes(i)
                If Not Application.Intersect(Range(.TopLeftCell, .BottomRightCell), ClearRange) Is Nothing Then
                    If .Type = msoFormControl Then
                        If .FormControlType = xlButtonControl Then
                            .Delete
                        End IF
                    End If
                End If
            End With
        Next i
    End With
    Good luck.

  5. #5
    Valued Forum Contributor
    Join Date
    02-20-2007
    Location
    South Africa
    MS-Off Ver
    2007
    Posts
    488

    Re: Delete Form Control Buttons in a range on worksheet

    @ mikerickson,

    I had a look at this Thread earlier but could not think of how to answer it.

    Your code looks perfect and I can't see anything wrong with it. Nice work!
    Please consider:

    Be polite. Thank those who have helped you. Click the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  6. #6
    Registered User
    Join Date
    12-26-2011
    Location
    Bangalore,India
    MS-Off Ver
    Excel 2007
    Posts
    27

    Re: Delete Form Control Buttons in a range on worksheet

    @onerrorgoto..!

    Using "Step-1" in place of ".shapes.count" did removed the error box, but it failed to remove the button form the range"A6:Y54"..!!

  7. #7
    Valued Forum Contributor Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds/Sheffield, England
    MS-Off Ver
    Excel 2003
    Posts
    1,031

    Re: Delete Form Control Buttons in a range on worksheet

    Really you should reference buttons rather than shapes, makes things faster:

    Dim ClearRange As Range
    Dim i As Integer
    Set ClearRange = ActiveSheet.Range("A6:Y54")
    
    With ClearRange.Parent
        For i = .Buttons.Count To 1 Step -1
            With .Buttons(i)
                If Not Application.Intersect(Range(.TopLeftCell, .BottomRightCell), ClearRange) Is Nothing Then .Delete
            End With
        Next i
    End With
    Last edited by Kyle123; 01-20-2012 at 04:14 AM.
    Click the * below to say thanks

    Girls sleep with guys who use photoshop, but marry the ones who work with Excel

    Corduroy
    pillows: They're making headlines!

    Did you mean: recursion
    http://www.google.com/search?hl=en&q=recursion

  8. #8
    Valued Forum Contributor OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,647

    Re: Delete Form Control Buttons in a range on worksheet

    Are you certain they are forms control buttons and not ActiveX ones?
    Good luck.

  9. #9
    Registered User
    Join Date
    12-26-2011
    Location
    Bangalore,India
    MS-Off Ver
    Excel 2007
    Posts
    27

    Re: Delete Form Control Buttons in a range on worksheet

    @kyle123

    Awesome..!! Thanks a lot , that really did the job.

  10. #10
    Registered User
    Join Date
    12-26-2011
    Location
    Bangalore,India
    MS-Off Ver
    Excel 2007
    Posts
    27

    Re: Delete Form Control Buttons in a range on worksheet

    @onerror..

    ya i m sure that they are form controls cause i am assigning macros to them..

  11. #11
    Valued Forum Contributor Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds/Sheffield, England
    MS-Off Ver
    Excel 2003
    Posts
    1,031

    Re: Delete Form Control Buttons in a range on worksheet

    @onError Microsoft usefully decided to hide forms controls from intellisense, they are still there you just have to show hidden objects
    Click the * below to say thanks

    Girls sleep with guys who use photoshop, but marry the ones who work with Excel

    Corduroy
    pillows: They're making headlines!

    Did you mean: recursion
    http://www.google.com/search?hl=en&q=recursion

  12. #12
    Registered User
    Join Date
    12-26-2011
    Location
    Bangalore,India
    MS-Off Ver
    Excel 2007
    Posts
    27

    Re: Delete Form Control Buttons in a range on worksheet

    Thanks a lot guys for all your help..!!
    You people are awesome VBA coders..!!!

  13. #13
    Valued Forum Contributor Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds/Sheffield, England
    MS-Off Ver
    Excel 2003
    Posts
    1,031

    Re: Delete Form Control Buttons in a range on worksheet

    No problem, thanks for the rep
    Click the * below to say thanks

    Girls sleep with guys who use photoshop, but marry the ones who work with Excel

    Corduroy
    pillows: They're making headlines!

    Did you mean: recursion
    http://www.google.com/search?hl=en&q=recursion

  14. #14
    Valued Forum Contributor OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,647

    Re: Delete Form Control Buttons in a range on worksheet

    Quote Originally Posted by Kyle123 View Post
    @onError Microsoft usefully decided to hide forms controls from intellisense, they are still there you just have to show hidden objects
    Thanks, but I know that (I use them all the time because I hate ActiveX).
    I just could not, and still cannot, see why Mike's version would not work given the tweak to step backwards. It should do exactly the same thing as your version.
    Good luck.

  15. #15
    Valued Forum Contributor Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds/Sheffield, England
    MS-Off Ver
    Excel 2003
    Posts
    1,031

    Re: Delete Form Control Buttons in a range on worksheet

    haha me too, I avoid ActiveX controls like the plague

    I agree and it does work fine for me when stepping backwards, I too have no idea why it doesn't work for the OP
    Click the * below to say thanks

    Girls sleep with guys who use photoshop, but marry the ones who work with Excel

    Corduroy
    pillows: They're making headlines!

    Did you mean: recursion
    http://www.google.com/search?hl=en&q=recursion

+ 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.2.0