The error probably came from my running the code with the sheet with the
Shape on it active and, perhaps, you were not doing so. This should fix the
problem I would think...
Dim RectangelIndexE10E11 As Long
Dim RectangleNameE10E11 As String
With Range("E10:E11")
Worksheets(1).Shapes.AddShape msoShapeRectangle, _
.Left, .Top, .Width, .Height
End With
With Worksheets(1)
RectangelIndexE10E11 = .Shapes.Count
RectangleNameE10E11 = .Shapes(Shapes.Count).Name
End With
By the way, the actual sheet names could be subsituted for the sheet index
number that I used. For example,
Dim RectangelIndexE10E11 As Long
Dim RectangleNameE10E11 As String
With Range("E10:E11")
Worksheets("Sheet1").Shapes.AddShape msoShapeRectangle, _
.Left, .Top, .Width, .Height
End With
With Worksheets("Sheet1")
RectangelIndexE10E11 = .Shapes.Count
RectangleNameE10E11 = .Shapes(Shapes.Count).Name
End With
Rick
Thanks Rick
That's certainly much neater than what I was trying to do.
BTW, I got a runtime error on this line:
RectangelIndexE10E11 = Shapes.Count
I didn't need that for my needs so I just took it out.
Al Stubna