+ Reply to Thread
Results 1 to 8 of 8

Subscript Out of Range Error

  1. #1
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Subscript Out of Range Error

    Hello:

    I am using below code and it is giving "Subscript out of range" error.
    Would appreciate help to resolve

    Please Login or Register  to view this content.
    Please let me know if you have any questions.
    Thanks.

    Riz

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Subscript Out of Range Error

    At what line do you get that message? And what does variable contain?

    That message is likely result of workbook/sheet name not being found.
    "Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something."
    ― Robert A. Heinlein

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Subscript Out of Range Error

    Most likely on this line

    ThisWorkbook.Sheets(CSheet).Range("C" & PasteR).Resize(RowsCnt, ColsCnt) = SrcRng.Value

    What is the value of CSheet = Range("K2").Value? Is it a string? Sheets(CSheet) name should be a string.
    What ever value is in K2 should match with existing sheet name. If it does not, the sheet names does not exist.
    Last edited by AB33; 11-10-2017 at 11:04 AM.

  4. #4
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Subscript Out of Range Error

    Hello:

    Below are all defined:

    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Subscript Out of Range Error

    Riz,
    In which line does the code error? Did you read my post 3?

  6. #6
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Subscript Out of Range Error

    Hello:

    AB33 : It does not show where the error occurs.
    Also all of them are defined and are according to your Post#3

    Just to let you know that once i press ok at the error, the macro will complete running and bring get the correct result.
    Its just annoying getting the error as i am designing to running this macro in a loop with lots of data/
    Please help to by-pass this error or may be help with new code.
    Please let me know if you have any questions.
    Thanks.

    Riz

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Subscript Out of Range Error

    Riz,
    Well, the code should come to halt as soon as it encounters an error.

    ThisWorkbook.Sheets(CSheet)=Range("K2").Value
    Let's say you have Range("K2").Value as sheet1 or riz .

    You should have a sheet name called sheet1 or riz in your sheet name collections.
    Any other I can think of is, you may rows exceeding 32k, in that case, you need to change the variables from integer to long.

  8. #8
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Subscript Out of Range Error

    Hello Guys:

    I found the problem and have resolved the issue.
    The problem was that when closed worksheet was being opened, it had the code to land at certain sheet and that sheet did not exist.
    Once again thanks a lot to point me to the right direction.
    Riz

+ 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 - 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
  2. Runtime Error - Subscript out of Range / Object Error
    By JHRice in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-04-2012, 05:14 PM
  3. 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
  4. 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
  5. 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
  6. Type Mismatch error & subscript out of range error
    By Jeff Wright in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-14-2005, 03:06 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