JS


Hi,

I have a macro that at one place creates new lines (the shape) on a sheet. My question is how can I group these lines. I have tried with something like this but I can not make the range function at the end work. As it is now I recieve an error '1004' The specified parameter has an invalid value.

Any ideas what to do

For i = 1 To myLegends.Count ''' draws the line
With ActiveSheet.Shapes.AddLine(BeginX(i), BeginY(i), EndX(i), EndY(i))
.Name = "MyLine" & i
End With
Next i


Dim shp As Shape
Dim sht As Worksheet
Dim tmp As String
Dim Lines() As String


Set sht = ActiveSheet
ReDim Lines(1)
i = 1
For Each shp In sht.Shapes
tmp = shp.Name
If Left(tmp, 6) = "MyLine" Then
Lines(i) = shp.Name
ReDim Preserve Lines(i + 1)
i = i + 1
End If

Next


ActiveSheet.Shapes.Range(Array(Lines)).Select

Thankful for help

Jonas





Re: group shapes

Andy Pope


Hi Jonas,

Try this revision.

Dim shp As Shape
Dim sht As Worksheet
Dim tmp As String
Dim Lines() As Variant
Dim i

Set sht = ActiveSheet
For Each shp In sht.Shapes
tmp = shp.Name
If Left(tmp, 6) = "MyLine" Then
ReDim Preserve Lines(i)
Lines(i) = shp.Name
i = i + 1
End If

Next

ActiveSheet.Shapes.Range(Lines).Group