Hi, I'm trying to select all the unwanted shapes in the range and I'm almost there but get stuck on one issue.
Example below, I'm trying to select all shapes that are aren't named Rectangle 1 and Rectangle 5 in range A1:O30 and it should select 3 shapes which are Rectangle 12 and Rectangle x 2. The problem with my code is that it won't select if the name is duplicate. Now, it is only select Rectangle 12 as Rectangle has 2 shapes with the same name. How do I adjust it to select all unwanted shapes even if it has duplicate name.
Here is my code, any suggestion will be much appreciated.
Thank you
Example below, I'm trying to select all shapes that are aren't named Rectangle 1 and Rectangle 5 in range A1:O30 and it should select 3 shapes which are Rectangle 12 and Rectangle x 2. The problem with my code is that it won't select if the name is duplicate. Now, it is only select Rectangle 12 as Rectangle has 2 shapes with the same name. How do I adjust it to select all unwanted shapes even if it has duplicate name.
Here is my code, any suggestion will be much appreciated.
Thank you
VBA Code:
Sub SelectunwatedShape()
Dim shp As Shape, r As Range, s As Range, myarr(), n As Integer
ReDim myarr(ActiveSheet.Shapes.Count)
Set r = Range("A1:O30")
ActiveCell.Select
For Each shp In ActiveSheet.Shapes
If Not Intersect(Range(shp.TopLeftCell, shp.BottomRightCell), r) Is Nothing Then
If shp.Name <> "Rectangle 1" And shp.Name <> "Rectangle 5" Then
myarr(n) = shp.Name
n = n + 1
End If
End If
Next shp
On Error Resume Next
ReDim Preserve myarr(n - 1)
ActiveSheet.Shapes.Range(myarr).Select
End Sub