• What is the macro code for selecting several objects

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » What is the macro code for selecting several objects

    Author
    Topic
    #460308

    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

    Viewing 0 reply threads
    Author
    Replies
    • #1163581

      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

    Viewing 0 reply threads
    Reply To: What is the macro code for selecting several objects

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: