Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Feb 2009
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts
    For example, this code only selects the last shape but I want to select all shapes that meet the criteria (then group them):

    Set a = ActiveSheet
    For each item in a.shapes
    If item.top > 500 then item.select 'add to a shaperange? how?
    Next item

  2. #2
    3 Star Lounger Jim Cone's Avatar
    Join Date
    Feb 2002
    Location
    Portland, Oregon, USA
    Posts
    238
    Thanks
    0
    Thanked 3 Times in 3 Posts
    You construct a shape range.
    The data type of the array must be a Variant.
    Selection is not required.
    '--
    Sub ComplicatedIsNotBetter()
    Dim a As Worksheet
    Dim arrShps() As Variant
    Dim N As Long
    Dim shpItem As Shape
    Dim shpRng As ShapeRange

    Set a = ActiveSheet
    ReDim arrShps(0 To a.Shapes.Count - 1)

    For Each shpItem In a.Shapes
    If shpItem.Top > 500 Then
    arrShps(N) = shpItem.Name
    N = N + 1
    End If
    Next 'shpItem

    ReDim Preserve arrShps(0 To N - 1)
    Set shpRng = a.Shapes.Range(arrShps())
    shpRng.Group
    MsgBox shpRng.Name & vbCr & shpRng.GroupItems.Count & " shapes"
    End Sub
    --
    Jim Cone
    Portland, Oregon USA

  3. #3
    Lounger
    Join Date
    Feb 2009
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Works great! Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •