I am trying to create a simple macro to delete some data including an Autoshape
- Shapes("ACCESS"), but I would like this macro to run only if Autoshape exists.
If it doesn't exist, the action would be just Range("B2").Select
Can anybody help please?
My Code
Sub DeleteRepWT()
ActiveSheet.Shapes("ACCESS").Select
Selection.ShapeRange.IncrementLeft 57#
Selection.ShapeRange.IncrementTop -85.5
Range("M4").Select
ActiveSheet.Shapes("ACCESS").Select
Selection.Delete
Columns("K:AI").Select
Selection.Delete Shift:=xlToLeft
Range("B2").Select
End Sub
You can use an object type shape, in my code it's
Shp, and try to set it toSet Shp = ActiveSheet.Shapes("ACCESS").Add
On Error Resume Nextbefore trying toSetthe shape object (so won't get a run-time error), and after trying toSetthe shape, you can checkIf Shp Is Nothing, which means checking if you were able toSetthe shape (if you weren't, it means there is noShapes("ACCESS")in your worksheet).Code