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.
Any help will be appreciated. Thanks.!!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
Last edited by abhiD; 01-20-2012 at 04:33 AM.
I believe this is the offending line.
.Shapes is a proprety of a Sheet object, not a Range object. Perhaps
Perhaps,For i = ActiveSheet.Range("A6:Y54").Shapes.Count To 1 Step -1
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.
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
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.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
M Stuck..![]()
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.
@ 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] .
@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"..!!
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
Are you certain they are forms control buttons and not ActiveX ones?
Good luck.
@kyle123
Awesome..!! Thanks a lot , that really did the job.
@onerror..
ya i m sure that they are form controls cause i am assigning macros to them..
@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
Thanks a lot guys for all your help..!!
You people are awesome VBA coders..!!!![]()
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
Good luck.
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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks