When I run the below macro (DeleteShapes) by itself, it does what I want. i.e. deletes all shapes in the specified range
Sub DeleteShapes()
Dim shp As Shape
For Each shp In Sheet1.Shapes
If Not Intersect(shp.TopLeftCell, Sheet1.Range("C13:P35")) Is Nothing Then
shp.Delete
End If
Next shp
End Sub
When I run the below Change event code which includes the DeleteShapes macro, it returns a 1004 Run-time error:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$F$11" Then
Application.EnableEvents = False
If Target.Value = "100 - Pay Change" Then
Call ProtectionOff
Call DeleteShapes
Call PayChange
Call ProtectionOn
ElseIf Target.Value = "140 - Education Pay" Then
Call ProtectionOff
Call DeleteShapes
Call EducationPay
Call ProtectionOn
End If
Application.EnableEvents = True
End If
End Sub
When I hit Debug on the error, It highlights the following code in the DeleteShapes macro:
If Not Intersect(shp.TopLeftCell, Sheet1.Range("C13:P35")) Is Nothing Then
Is there any way to diagnose which specific part of the above line of code is causing the error? I suspect it might have to do with the TopLeftCell section.
Bookmarks