+ Reply to Thread
Results 1 to 15 of 15

Run Time error 9 : subscript out of range

  1. #1
    Registered User
    Join Date
    01-04-2013
    Location
    Vancouver, BC
    MS-Off Ver
    Excel 2010
    Posts
    7

    Run Time error 9 : subscript out of range

    First post - hi everyone

    I am getting this error on my first line of code! (see below) but can't figure out why. Is it because I am prompted to enable macros whenever I manually open this book, or because I am not referencing a sheet? Or because it is a 97-2003 running in Excel 2010?


    Please Login or Register  to view this content.
    Any ideas appreciated. Thanks.
    Last edited by exec_gerbil; 01-04-2013 at 03:32 PM.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Run Time error 9 : subscript out of range

    A subscript out of range error occurs whenever your filename or sheet name in the code does not match the actual file or sheet. Check that the filename matches your file.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    01-04-2013
    Location
    Vancouver, BC
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Run Time error 9 : subscript out of range

    Thanks Arlette. I've changed the name to something simpler - easier to notice the typos!

    Also apologies, will edit previous and tag the code.

  4. #4
    Registered User
    Join Date
    01-04-2013
    Location
    Vancouver, BC
    MS-Off Ver
    Excel 2010
    Posts
    7

    Question Re: Run Time error 9 : subscript out of range

    Arlette,


    I'm getting this error again.

    The only thing that has changed is that the workbook has been copied on to another network drive and is in use there too.

    After checking and rechecking the spelling of the file name, I'm stumped! Any ideas?

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Run Time error 9 : subscript out of range

    Why do you need to activate the file? Can you provide me the further lines of code so i can help you edit it?

  6. #6
    Registered User
    Join Date
    01-04-2013
    Location
    Vancouver, BC
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Run Time error 9 : subscript out of range

    Hi Arlette,

    Really appreciating your willingness to engage on this! Actually this is my first month on the job and it's not my code, nor can I contact the author - just keeping it going until I have time to refactor it. Here it is:

    Please Login or Register  to view this content.
    ....and so on, let me know if you need more. The author uses the Activate method to change the active workbook. In order to break the VBA Project password protection, I had to resave this Excel 2010 workbook as a 97-2003 workbook. Perhaps this is the issue?

    Thanks again!

  7. #7
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Run Time error 9 : subscript out of range

    Check if the file is having a .xls extension or is it still .xlsx.

  8. #8
    Registered User
    Join Date
    01-04-2013
    Location
    Vancouver, BC
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Run Time error 9 : subscript out of range

    Nope, that's not it, I tried .xlsx and .xlsm and I'm still getting the same error.

    I haven't used the activate method before, perhaps it's new to 2010 and so doesn't work when you SaveAs an xls? That's all I can think of. Anyone? Anyone?.....

  9. #9
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Run Time error 9 : subscript out of range

    You marked this solved? Is it solved?

  10. #10
    Registered User
    Join Date
    01-04-2013
    Location
    Vancouver, BC
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Run Time error 9 : subscript out of range

    Quote Originally Posted by arlu1201 View Post
    You marked this solved? Is it solved?
    It was but the problem recurred and the original solution is not working this time.

    AND the plot thickens...nothing is open but I am getting this error when I tried to save over a previous version:

    Microsoft Excel cannot access the file "M:\CV Factors BM annotated macros.xls'

    - The file name or path does not exist
    - The file is being used by another program.
    - The workbook you are trying to save has the same name as a currently open workbook.



    Could this be related, and this whole thing is some kind of network access issue? I am completely ignorant in that area and no idea how to even begin checking.


    Thanks again for any suggestions,

    Joanna
    Last edited by exec_gerbil; 01-15-2013 at 01:37 PM. Reason: additional information today!

  11. #11
    Registered User
    Join Date
    01-04-2013
    Location
    Vancouver, BC
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Run Time error 9 : subscript out of range

    OK this is embarassing but I am posting to help all the other noobs out there...didn't realize that you had to have all referenced sheets open in the same instance of Excel for the macro to run with this method.

    Duh.

    Anyway thanks for the support!

  12. #12
    Registered User
    Join Date
    01-06-2014
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    12

    Thumbs up Re: Run Time error 9 : subscript out of range

    Quote Originally Posted by arlu1201 View Post
    A subscript out of range error occurs whenever your filename or sheet name in the code does not match the actual file or sheet. Check that the filename matches your file.
    Thanks so much, arlu1201! I was also having this issue--my client couldn't run the code and I could, even though we both have Office 2013--turns out he'd renamed the spreadsheet, and the name was in my code. THANK YOU THANK YOU.

  13. #13
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Run Time error 9 : subscript out of range

    You are welcome DaynaBarnes. Thanks for the rep.

  14. #14
    Registered User
    Join Date
    03-04-2013
    Location
    usa
    MS-Off Ver
    Excel 2016
    Posts
    39

    Re: Run Time error 9 : subscript out of range

    I am getting this error "Run Time error 9 : subscript out of range " when I start excel or when I open a spread sheet.
    running office 2016 on windows 7

  15. #15
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,936

    Re: Run Time error 9 : subscript out of range

    Quote Originally Posted by i.r.smith View Post
    I am getting this error "Run Time error 9 : subscript out of range " when I start excel or when I open a spread sheet.
    running office 2016 on windows 7
    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #1 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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