+ Reply to Thread
Results 1 to 6 of 6

Subscript Out of Range (Error) when running a macro

  1. #1
    Forum Contributor
    Join Date
    06-15-2013
    Location
    United States
    MS-Off Ver
    Excel 2016
    Posts
    214

    Subscript Out of Range (Error) when running a macro

    Hello Everybody,
    Can somebody please help me with the following error. I have macro that is checking column F for a user's name and then transferring the data found in that row to the corresponding Sheet with that name. So if the user's name is Tim it will look for the Sheet with that exact name and transfer the information to that file. This macro works fine with my test data when I just typed in the information but when I tried to copy and paste the data into the cells and then run the macro I get the Subscript Out of Range(error) Can someone please help me on what is going on.Capture.PNG

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Subscript Out of Range (Error) when running a macro

    What is c.Value when you get the error?

    If it's not the name of a sheet in the active workbook you'll get the subscript out of range error.

    You might also get an error if your sheet names are numeric and c.Value is also numeric.
    If posting code please use code tags, see here.

  3. #3
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Subscript Out of Range (Error) when running a macro

    Perhaps one of the names in Column F doesn't have a Sheet named after it?

  4. #4
    Forum Contributor
    Join Date
    06-15-2013
    Location
    United States
    MS-Off Ver
    Excel 2016
    Posts
    214

    Re: Subscript Out of Range (Error) when running a macro

    I can see that on the backend its numeric but It's just confusing me because it works fine when I type the information in. But if I try to copy and paste the data from another file it comes up with the error. This is the coding I have running in other portions of the overall macro.
    Please Login or Register  to view this content.
    As you can see I'm calling the Sheets by Sheet1 and Sheet2.

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Subscript Out of Range (Error) when running a macro

    If the value in the cell is numeric then when you use Sheets(c.Value) VBA will regard c.Value as the Index of the sheet, not the name.

    To use the value as the name of the sheet use CStr, Sheets(CStr(c.Value)).

  6. #6
    Forum Contributor
    Join Date
    06-15-2013
    Location
    United States
    MS-Off Ver
    Excel 2016
    Posts
    214

    Re: Subscript Out of Range (Error) when running a macro

    Quote Originally Posted by Norie View Post
    If the value in the cell is numeric then when you use Sheets(c.Value) VBA will regard c.Value as the Index of the sheet, not the name.

    To use the value as the name of the sheet use CStr, Sheets(CStr(c.Value)).
    Hey Norie,

    Appreciate your response. Is there a way you can send me what my coding should look like with your coding so I don't screw it up and cause myself more problems. I appreciate your help.

+ 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] Macro - Subscript out of range error
    By hariprasadcp in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-24-2013, 08:15 AM
  2. 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
  3. 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
  4. fix a macro that gets a run-time error '9' subscript out of range
    By kellys in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-09-2006, 03:55 PM
  5. 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

Tags for this Thread

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