+ Reply to Thread
Results 1 to 12 of 12

run-time error '9':

  1. #1
    Registered User
    Join Date
    05-14-2017
    Location
    Philippines
    MS-Off Ver
    2010
    Posts
    10

    run-time error '9':

    I was reading one excel vba book and opened two workbooks(book1 and Book2). I happened to come across a code to copy and paste a range between the said workbooks:

    Please Login or Register  to view this content.
    When I ran the abovecode it produced
    run-time error '9':
    Subscripts out of range.

    Can anyone help me fix this error.
    Last edited by jeffreybrown; 05-21-2017 at 09:33 AM. Reason: Please use code tags!

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,087

    Re: run-time error '9':

    What are the workbook names and the worksheet names? Do you actually have File1.xlsx and File2.xlsx? If not, that's your problem.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    05-14-2017
    Location
    Philippines
    MS-Off Ver
    2010
    Posts
    10

    Re: run-time error '9':

    Good day sir!

    I edited these lines:

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.
    but I still got the same run-time error '9': subscripts out of range.
    Last edited by jeffreybrown; 05-21-2017 at 09:35 AM. Reason: Please use code tags when posting code!

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,087

    Re: run-time error '9':

    If you have only opened two new workbooks but not saved them, they won't actually be recognised as Book1.xlsx and Book2.xlsx.

  5. #5
    Registered User
    Join Date
    05-14-2017
    Location
    Philippines
    MS-Off Ver
    2010
    Posts
    10

    Re: run-time error '9':

    Thank you very much sir! It did work after I have saved the two workbooks before I ran the code.

    Sir may I ask if you could help me further with a code that could copy say,

    Please Login or Register  to view this content.
    Thank you very much sir!
    God bless you!
    Last edited by jeffreybrown; 05-21-2017 at 09:35 AM. Reason: Please use code tags when posting code!

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,087

    Re: run-time error '9':

    Try:

    Please Login or Register  to view this content.

  7. #7
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: run-time error '9':

    lynyrdskynyrd5,

    Please use code tags when posting code!
    HTH
    Regards, Jeff

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,087

    Re: run-time error '9':

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  9. #9
    Registered User
    Join Date
    05-14-2017
    Location
    Philippines
    MS-Off Ver
    2010
    Posts
    10

    Re: run-time error '9':

    Thank you sir!
    Sir how about if I copy the same abovecells in sheet1 to the same abovecells location in sheet2 but this time both sheets are in the same workbook, how will I modify the above code you shared to me.
    Thank you again sir!
    God bless you!

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,087

    Re: run-time error '9':

    Think about it and try it for yourself. Otherwise, you're never going to learn how to do it.

    What do you think you should change wb2sh1 to? Maybe .Sheets(2) ...? Why?

    And then you don't need wb2 or wb2sh1, do you? So you can remove the Dim and Set for them.

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,087

    Re: run-time error '9':

    Please: no more new questions in this thread, even if they are variations on a theme.


    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  12. #12
    Registered User
    Join Date
    05-14-2017
    Location
    Philippines
    MS-Off Ver
    2010
    Posts
    10

    Re: run-time error '9':

    Thank you very much for the help sir!
    Your code helps me do my work faster.
    Thanks again!

+ 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] Error message: Run-Time error '1004 '; application-defined or object-defined error
    By Davasu in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-23-2015, 06:52 AM
  2. Replies: 1
    Last Post: 10-22-2015, 05:50 AM
  3. VBA ERROR: run time error 1004: Application-defined or Object-defined error in excel 2013
    By AnanthKrishna in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-13-2015, 06:16 AM
  4. Cannot Publish Excel Pivot Chart - Run Time Error
    By crisb184 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-11-2013, 07:04 AM
  5. [SOLVED] Error " Run-time error '1004': application defined or object defined error
    By lengwer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-11-2013, 07:26 AM
  6. run-time error ;2147023179 (800706b5) time automation error interface unknown
    By karthik72 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-02-2012, 09:31 AM
  7. 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

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