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
 

Some videos you may like

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

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
 

Watch MrExcel Video

Forum statistics

Threads
1,109,550
Messages
5,529,472
Members
409,884
Latest member
Msinmath
Top