+ Reply to Thread
Results 1 to 5 of 5

Subscript out of range error

  1. #1
    Forum Contributor
    Join Date
    02-01-2021
    Location
    Manchester
    MS-Off Ver
    365
    Posts
    218

    Subscript out of range error

    The following two sub routines are used to remove some formulae from a sheet whilst it is being copied to another workbook, and to replace them after the copying.
    Please Login or Register  to view this content.
    The first sheet involved in this is "TapeBudgetA" and when the code reaches the copy line marked with xxx an error message "Subscript out of range" shows.
    The sheet "Utilities" exists and the range contains the desired information so I cant understand where I have gone wrong. Can anyone help?
    John

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,777

    Re: Range not accepted

    References to objects should be explicitly qualified. The default is different depending on context. You mention working with another workbook.

    Without qualification, all references to Sheets will be assumed to be in the ActiveWorkbook, which may be different than the workbook containing the code.

    • What workbook contains the code?
    • What workbook contains the sheets TapeBudgetA and Utilities?
    • What workbook is active when you run this code?


    If the workbook with the code is the one containing those sheets, then you should either 1) guarantee that this workbook is active when you run the code, or 2) change Sheets to ThisWorkbook.Sheets.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,777

    Re: Subscript out of range error

    P.S. I have updated your title because your title pointed to the Range but in reality the error is caused by the Sheets reference. Best to describe what you are seeing rather than an assumption of what the problem is.

  4. #4
    Forum Contributor
    Join Date
    02-01-2021
    Location
    Manchester
    MS-Off Ver
    365
    Posts
    218

    Re: Subscript out of range error

    6String Jazzer
    Many thanks for your help. I changed the code to make sure there was no doubt which workbook/worksheet the range was in and all worked as wanted.
    John

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,777

    Re: Subscript out of range error

    Good news. Glad I could help.

    If your question has been answered please mark your thread as "Solved" so that members will know by looking at the thread title that your problem is solved. Go to the menu immediately above your first post to the thread and click on Thread Tools. From the dropdown menu select "Mark this thread as solved..."

    If a member helped you solve your problem, consider adding to their reputation by clicking addreputationiconsmall.jpg below their name.

+ 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. Error code "run time error 9: subscript out of range
    By iBennett93 in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 06-28-2021, 05:03 AM
  2. [SOLVED] Help with error run-time error '9" (subscript out of Range)
    By thong127 in forum Excel General
    Replies: 7
    Last Post: 05-02-2018, 02:17 PM
  3. [SOLVED] Run-time error '9': subscript out of range - error occurs on multiple computers except one
    By BrettE in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-06-2014, 11:19 PM
  4. Defining Array - Runtime error 9, Subscript out of range error
    By MaartenW in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-03-2012, 07:32 AM
  5. Runtime Error - Subscript out of range despite On Error statement
    By DoctorG in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-28-2006, 11:05 AM
  6. Subscript out of range error - save copy error
    By bg18461 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-13-2006, 11:53 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