Deleting an Autoshape with VBA in Excel 2003

stirlingmw

Board Regular
Joined
Feb 18, 2013
Messages
75
I have the following code attached to a commandbutton on a sheet which clears the content of a selected cell and if an autoshape is present this is deleted too.
My problem is when I designed the spreadsheet at home I was running Office 2013, but at work where I use the spreadsheet they run Office 2003 and this part of the code does not seem to work, any ideas??
Private Sub ClearSelectionFill()
Dim sh As Shape

Selection.Interior.Color = xlNone
Selection.ClearContents
For Each sh In ActiveSheet.Shapes
If Not Intersect(Selection, sh.TopLeftCell) Is Nothing Then
sh.Delete
End If
Next sh
End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hi stirlingmw,

The code you posted should work fine in either version of Excel. In addition I tested it in 2003 and it worked without error.

What kind of error are you getting?

Damon
 
Upvote 0
It goes to debug, and highlights

If Not Intersect(Selection, sh.TopLeftCell) Is Nothing Then

Stirling
 
Upvote 0

Forum statistics

Threads
1,214,922
Messages
6,122,281
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top