+ Reply to Thread
Results 1 to 6 of 6

"Run-time error '9': Subscript out of range" when referencing between workbooks

  1. #1
    Registered User
    Join Date
    08-07-2014
    Location
    Canada
    MS-Off Ver
    Office 2010
    Posts
    2

    "Run-time error '9': Subscript out of range" when referencing between workbooks

    Hello,

    I'm developing a more streamlined invoicing system for a friend where information from an invoicing template ("InvoiceTemplate_CompanyName.xlsm") is copied to an excel document summarizing all of their invoices ("InvoiceSummary_CompanyName.xlsx"). I have gotten this to work exactly as I want it on the computer that I've been developing the solution on, but I had an embarrassing moment when trying to transfer the files to my friends computer (i.e., the computer that will end up hosting the excel files). I thought that I would just need to change the path names to those of the new computer, but it did not work. When trying to execute the code, I kept getting a "Run-time error '9': Subscript out of range" error.

    The one thing that I think the problem could be related to is the setup I've been using to develop the VBA solution. I've been using a mac running windows 7 through virtualbox. I've been writing the VBA code in Excel 2010 on the windows side. Like I said, the code worked on my mac (running windows 7), just not on my friends computer. I can't remember, but my friend might have also been running Excel 2013....could there be an issue with my code being developed in Excel 2010?

    Thanks in advance for any advice on this issue!

    Here is the code:

    [FONT=Courier New]
    Please Login or Register  to view this content.

    'This function is used to see if "InvoiceSummary_CompanyName.xlsx" is already open or not.
    Please Login or Register  to view this content.
    Last edited by alansidman; 08-07-2014 at 10:50 PM. Reason: code tags added

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,884

    Re: "Run-time error '9': Subscript out of range" when referencing between workbooks

    Code Tags Added
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (Because you are new to the forum, I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Contributor lancer102rus's Avatar
    Join Date
    04-02-2014
    Location
    Ufa
    MS-Off Ver
    Excel 2010, 2013
    Posts
    252

    Re: "Run-time error '9': Subscript out of range" when referencing between workbooks

    1) put you code into spoiler
    2) Workbooks("InvoiceSummary_CompanyName") => Workbooks("InvoiceSummary_CompanyName.xlsx")
    Last edited by lancer102rus; 08-07-2014 at 10:52 PM. Reason: #1 done

  4. #4
    Forum Contributor mongoose36's Avatar
    Join Date
    06-10-2013
    Location
    Lincoln
    MS-Off Ver
    Excel 2013
    Posts
    389

    Re: "Run-time error '9': Subscript out of range" when referencing between workbooks

    The use of code tags makes it easier for others to see your code.
    To place code in code tags click to edit your post --> highlight the section of code --> click on the hashtag button or pound symbol in the WYSIWYG editor.

    You should really declare and initialize variables to avoid confusion. For example...

    Please Login or Register  to view this content.
    By declaring and initializing your variables clearly you can always refer to exactly what you want at any time in the code easily
    If your questions has been answered to your satisfaction please don't forget to do the following:

    Add Reputation ... and ... Mark Thread as Solved

    Thanks,

    Ma 10:8b Freely you have received; freely give.

  5. #5
    Registered User
    Join Date
    08-07-2014
    Location
    Canada
    MS-Off Ver
    Office 2010
    Posts
    2

    Re: "Run-time error '9': Subscript out of range" when referencing between workbooks

    Thanks for the feedback cplettner. I do apologize for not adding the code tags, this is my first post to excelforum. I've just recently learned some of the basics in VBA coding in excel, and I think I get easily carried away with applying basic techniques when other techniques would serve me better. I really appreciate you adding to the code and I will try your modifications to clean it up and see if it resolves the error I was getting. Just for my understanding of the Run-time error '9', was there something specifically in my code that caused this?

    Thanks again for the help.

  6. #6
    Forum Contributor mongoose36's Avatar
    Join Date
    06-10-2013
    Location
    Lincoln
    MS-Off Ver
    Excel 2013
    Posts
    389

    Re: "Run-time error '9': Subscript out of range" when referencing between workbooks

    Thanks for the feedback cplettner. I do apologize for not adding the code tags, this is my first post to excelforum. I've just recently learned some of the basics in VBA coding in excel, and I think I get easily carried away with applying basic techniques when other techniques would serve me better. I really appreciate you adding to the code and I will try your modifications to clean it up and see if it resolves the error I was getting. Just for my understanding of the Run-time error '9', was there something specifically in my code that caused this?
    In the following line you are missing the file extension

    Please Login or Register  to view this content.
    Should be

    Please Login or Register  to view this content.

+ 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] "run time error 9 subscript out of range" Help?
    By AMV in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-24-2014, 04:54 PM
  2. Replies: 1
    Last Post: 12-15-2011, 10:59 AM
  3. Error msgs: "Object varible or with block variable not set"; "subscript out of range"
    By menyanthe in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-26-2009, 04:58 PM
  4. [SOLVED] "Subscript out of range" error for: Workbooks("Test1.xls").Save
    By Just12341234 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-17-2005, 11:05 AM
  5. FileCopy Command Giving "Subscript Out of Range" Error Message
    By Jim Hagan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-15-2005, 02: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