+ Reply to Thread
Results 1 to 3 of 3

Application error 1004 due to a drop down box.

Hybrid View

  1. #1
    Registered User
    Join Date
    06-06-2014
    Location
    Hong Kong
    MS-Off Ver
    2010
    Posts
    91

    Application error 1004 due to a drop down box.

    I have this code I found and altered it for my use.
    My requirement was to select every shape but a button linked to the macro and group them together since the number of shapes can change with what I select in my excel sheet (It creates a collated diagram).

    Dim vShapesToExclude As Variant
    Dim aShapesToSelect() As String
    Dim oShape As Shape
    Dim vMatchVal As Variant
    Dim ShpCnt As Integer: ShpCnt = 0
    
    vShapesToExclude = Array("Button 1")
    
    ReDim aShapesToSelect(1 To ActiveSheet.Shapes.count)
    
    For Each oShape In ActiveSheet.Shapes
        vMatchVal = Application.Match(oShape.Name, vShapesToExclude, 0)
        If IsError(vMatchVal) Then
            ShpCnt = ShpCnt + 1
            aShapesToSelect(ShpCnt) = oShape.Name
        End If
    Next oShape
    
    ActiveSheet.Shapes.Range(aShapesToSelect()).Select
    ActiveSheet.Shapes.Range(aShapesToSelect()).Group
    This works fine if I change nothing in the excel sheet but the moment I click on my drop down box, and I don't even need to change anything, it breaks giving me the classic 1004 error.

    I had a look into what was causing this with "debug.print" on the "aShapesToSelect" array thinking maybe something was empty, instead I'm met with a log of "Drop down" instead of "textbox" causing the issues.

    I have absolutely no idea what is causing the switch over and I can only get it working again if I recompile the code to "reset" the selection.

    Any assistance is appreciated, thanks.
    Last edited by Gunblade; 05-11-2021 at 03:02 AM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: Application error 1004 due to a drop down box.

    I'm guessing you're talking about a data validation dropdown? Try looping through the sheet's DrawingObjects collection instead.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Registered User
    Join Date
    06-06-2014
    Location
    Hong Kong
    MS-Off Ver
    2010
    Posts
    91

    Re: Application error 1004 due to a drop down box.

    Looks like that's solved it, much appreciated.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] 1004 run-time error, Application or object-defined error
    By SimChengKeng in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-09-2019, 07:33 AM
  2. Run-time error 1004 error on Mac only Application.Get.Save.AsFilename
    By Carpinteria Al in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-04-2016, 11:20 AM
  3. [SOLVED] Sort Macro Run-time error '1004': Application/Object-defined error.
    By sam1212 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-22-2014, 10:05 AM
  4. [SOLVED] Getting Error 1004 Object or Application Defined Error - Code to rearrange data
    By BlazzedTroll in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 06-10-2013, 12:10 PM
  5. error 1004 application defined error (Moving click button)
    By mdavid800 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-08-2011, 10:13 AM
  6. [SOLVED] Error 1004, Application-definded or object-defined error
    By Mirco Wilhelm in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-07-2006, 01:00 PM
  7. [SOLVED] run-time error '1004': Application-defined or object-deifined error
    By rich5665@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-10-2005, 05: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