Results 1 to 6 of 6

Select all shapes with similar names: Runtime error 1004

Threaded View

  1. #1
    Registered User
    Join Date
    03-22-2019
    Location
    Los Angeles
    MS-Off Ver
    2013
    Posts
    34

    Question Select all shapes with similar names: Runtime error 1004

    I am having trouble selecting only the shapes that contain a specific string within the name. The red line in the code is my problem.
    I am searching for all the shapes within the sheet, storing the names of the shapes I wan't in an array and placing the join output of the array into a string. I can't get past this point.

    Sub autoAlignShapes2323()
        Dim shp As Shape
        Dim ws As Worksheet
        Dim iButtonNames As Variant
        Dim cnt As Byte
        Dim btnStr As String
        
        ReDim iButtonNames(1)
        Set ws = Sheet1
        cnt = 0
        
        For Each shp In ws.Shapes
            Debug.Print shp.Name
            If InStr(1, shp.Name, "_Sheet", vbTextCompare) > 1 Then
                ReDim Preserve iButtonNames(cnt)
                iButtonNames(cnt) = Chr(34) & shp.Name & Chr(34)
                cnt = cnt + 1
            End If
        Next
    
        btnStr = Join(iButtonNames, ", ")
        Debug.Print btnStr & vbNewLine & TypeName(btnStr)
        ws.Shapes.Range(Array(btnStr)).Select
    
    End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Runtime Error 1004 + Runtime 5
    By jrean042 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-07-2020, 08:16 AM
  2. [SOLVED] RunTIme Error 1004 when asked to select ".range"
    By Ochimus in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-10-2018, 07:55 AM
  3. Error 1004: ActiveSheet.Shapes.AddChart.Select
    By andynewtovba in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-02-2015, 12:08 PM
  4. [SOLVED] ActiveSheet.Shapes.AddChart.Select Run-Time Error '1004'
    By bcn1988 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-07-2013, 11:30 AM
  5. Excel VBA Runtime error 1004 "Select method of Range class failed"
    By jeskit in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-09-2012, 10:16 AM
  6. Error: Runtime 1004 - Select method of range class failed
    By additude in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-18-2008, 05:58 PM
  7. [SOLVED] Runtime Error 1004 Select method of Range class Failed
    By IanO in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-16-2005, 04:05 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1