PDA

View Full Version : Sleeper: Code not deleting shape



Juriemagic
07-28-2015, 03:46 AM
Hi there,

I have this code:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("AL10")) Is Nothing Then
If Range("AL2") = 1 Or Range("AL2") = 2 Then
If Range("AP2") = 0 Then
application.ScreenUpdating = False
ActiveSheet.Shapes.AddShape(msoShapeRectangle, 1850, 150, 150, 100).Select
With Selection.ShapeRange.Fill
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorBackground1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = -0.150000006
.Transparency = 0
.Solid
End With
Selection.ShapeRange.Line.Visible = msoFalse
Selection.ShapeRange.Name = "Scooby"
Range("AP2").Select
ActiveCell.FormulaR1C1 = 1
Range("AL10").Select
End If
If Not Intersect(Target, Range("AL10")) Is Nothing Then
If Range("AL2") > 2 And Range("AP2") = 1 Then
application.ScreenUpdating = False
ActiveSheet.Shapes.Range(Array("Scooby")).Select
Selection.Delete
Range("AP2").Select
ActiveCell.FormulaR1C1 = 0
Range("AL10").Select
Exit Sub
End If
End If
End If
End If
End Sub


The first half works, but the second half to delete the shape refuses to work. I have tried various alterations except the correct one. Please help me to get the latter part right to delete the shape when certain condition exists. I will be forever grateful!!..thank you all..