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

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Damon Ostrander

MrExcel MVP
Joined
Feb 17, 2002
Messages
4,239
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
 

stirlingmw

Board Regular
Joined
Feb 18, 2013
Messages
75
It goes to debug, and highlights

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

Stirling
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,601
Messages
5,838,300
Members
430,537
Latest member
Antonio11

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
Top