+ Reply to Thread
Results 1 to 4 of 4

Range error in code, runs alone but not inside my full program, giving runtime error 1004

  1. #1
    Registered User
    Join Date
    08-23-2012
    Location
    dc
    MS-Off Ver
    Excel 2010
    Posts
    2

    Range error in code, runs alone but not inside my full program, giving runtime error 1004

    First off this is my first post so "Hello World" (of vba help), sorry I won't tell anymore bad jokes, promise. Anyway I am just starting out in vba but am making a simple program to open a directory and copy and paste columns to a new workbook. The code executes a full loop where the line in question is skipped by conditions in an if statement, everything works fine. The second iteration goes to the problematic range line in my if statement and i get the run-time error '1004' application-defined or object-defined error window. I think this has to be referencing the object range but I can't figure out why it isn't working. I have copied the code line that gives the error and put into a new sub by itself and it runs perfectly fine.

    This is the range code line that gives the error:

    Please Login or Register  to view this content.
    its a pretty straight forward selection of a cell to the right of the last used cell. I am guessing the error has something to do with the objects being declared in my program but I can't figure it out. It has really been puzzling me so I hope you guys and gals can help! Here is the full code (took out my working path in the filesystem object and replaced it with the word path for privacy reasons):

    Please Login or Register  to view this content.


    Thanks and I hope someone can help!!

  2. #2
    Valued Forum Contributor
    Join Date
    05-07-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    354

    Re: Range error in code, runs alone but not inside my full program, giving runtime error 1

    try

    Please Login or Register  to view this content.
    Regards,
    Vandan

  3. #3
    Registered User
    Join Date
    08-23-2012
    Location
    dc
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Range error in code, runs alone but not inside my full program, giving runtime error 1

    that works! thank you for your help. Why did range not work/ cells and active sheet did?

  4. #4
    Valued Forum Contributor
    Join Date
    05-07-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    354

    Re: Range error in code, runs alone but not inside my full program, giving runtime error 1

    I think may be

    Please Login or Register  to view this content.
    .end(xltoright) was going to the last column then trying to offset to one more column with the offset function

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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