+ Reply to Thread
Results 1 to 3 of 3

Run Time Error 1004

  1. #1
    Registered User
    Join Date
    09-30-2015
    Location
    London
    MS-Off Ver
    2010
    Posts
    2

    Question Run Time Error 1004

    Hi, I'm trying to run a macro but I am receiving the Run Time Error 1004: Application-defined or object-defined error. When the error appears it doesn't indicate the line of code that's causing the problem, but by running the two halves of the macro seperately I have identified the error to be in the second half of the code.

    Please Login or Register  to view this content.
    From reading other peoples' posts about this type of error I presumed it was being caused by the worksheet not being defined or activated, but if that is the cause I haven't been able to adequately resolve it. Would appreciate any assistance that could be provided.

    Thanks in advance.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Run Time Error 1004

    Hi Stanlee,

    I wonder if you are trying to make your code work on the active worksheet or on the ws sheet? After doing your "Set ws = .." statement it looks like you want your for/next loop to work on the ws sheet.

    To do this you need to use the WITH construct and a period in front of the Range word in your code. This is a very small change to your code but is very important to Excel VBA.

    Example
    For My_Rows = Range("Q4705").End(xlUp).Row To 11 Step -1 ' This code works on the active sheet or the one you are looking at

    With ws
    For My_Rows = .Range("Q4705").End(xlUp).Row To 11 Step -1 ' This code works on the ws that is set with the "With" statement
    End With

    I'm totally guessing what you are trying to do but feel this is what is happening.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    09-30-2015
    Location
    London
    MS-Off Ver
    2010
    Posts
    2

    Re: Run Time Error 1004

    Hi MarvinP, thanks for the quick response. The "Set ws = .." was a hangover from when I tried to define the active sheet and then define the range doing the mergining and selecting thinking that would sort the problem but unfortunately I still received the same run time error. I tried to put everything back the way it was but must have forgotten a couple of statements at the beginning. Below should be the original code:

    Please Login or Register  to view this content.
    Apologies for any confusion.

+ 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] 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
  2. Addon error : Run-time error '1004': Method 'MacroOptions' of object '_Application' failed
    By jtcoleman in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 3
    Last Post: 02-05-2014, 12:23 PM
  3. Replies: 4
    Last Post: 11-15-2013, 05:03 PM
  4. VBA Code...error = run time error 1004 autofilter method of range class failed
    By Dariusd7 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-15-2013, 04:49 PM
  5. Error "run-time Error '1004': General Odbc Error
    By D4WNO77 in forum Access Tables & Databases
    Replies: 2
    Last Post: 07-16-2012, 09:55 AM
  6. Excel Macro Error - Run time error 1004 - Paste method of worksheet class failed
    By kvflynn in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-15-2012, 10:51 AM
  7. 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