+ Reply to Thread
Results 1 to 8 of 8

Run time error '9': Subscript out of Range

  1. #1
    Registered User
    Join Date
    06-24-2015
    Location
    Wisconsin
    MS-Off Ver
    Excel 2013
    Posts
    49

    Run time error '9': Subscript out of Range

    I"m getting the following error on my VBA:

    Run time error '9': Subscript out of Range.

    I'm sure it has something to do with the fact that for the data that I"m dealing with there is not a WS2 which holds "Y" because this data doesn't have Y values. I Need to figure out how to have the process ignore if there is no WS2 or WS1 to not error out.
    Please Login or Register  to view this content.
    Last edited by alansidman; 09-30-2016 at 11:42 AM. 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 insider Version 2504 Win 11
    Posts
    24,705

    Re: Run time error '9': Subscript out of Range

    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



    ( 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 Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Run time error '9': Subscript out of Range

    Where in the code do you get the error?
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    06-24-2015
    Location
    Wisconsin
    MS-Off Ver
    Excel 2013
    Posts
    49

    Re: Run time error '9': Subscript out of Range

    Right after
    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: Run time error '9': Subscript out of Range

    It means the sheet does not exist. You need to check the spelling name of the sheet y.

    This line
    Dim WS1, WS2 As Worksheet
    also means, only WS2 is declared as worksheet, but WS1 is declared as variant.

    should be

    Dim WS1 As Worksheet, WS2 As Worksheet

  6. #6
    Registered User
    Join Date
    06-24-2015
    Location
    Wisconsin
    MS-Off Ver
    Excel 2013
    Posts
    49

    Re: Run time error '9': Subscript out of Range

    I changed it to
    Please Login or Register  to view this content.
    but I"m still getting the error. I know that Y sheet doesn't exist for this set of data. That's why I have the if not WS1 is nothing... same for WS2 is nothing... but I"m still getting the error.

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

    Re: Run time error '9': Subscript out of Range

    If there is no worksheet named 'Y' you can't use Worksheets("Y").

  8. #8
    Registered User
    Join Date
    06-24-2015
    Location
    Wisconsin
    MS-Off Ver
    Excel 2013
    Posts
    49

    Re: Run time error '9': Subscript out of Range

    I have a procedure before that will split the data into sheets based on the value in column H. Guess what I"ll have to do is have it do a certain set of code if there are both Ns and Ys in column H, if there is only N's and if there are only Ys. I thought adding an If statement to see if there isn't a worksheet for Y or N that it just ignored that. The values in the file will always be Y or N. there may be files that have both Y lines and N lines.

+ 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. Run-time error 9 subscript out of range
    By LeonHeart93 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-29-2016, 03:44 AM
  2. [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
  3. Run-time error 9: Subscript out of Range
    By boesingen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-14-2013, 09:41 AM
  4. [SOLVED] Run time error 9 subscript out of range
    By cgabe001 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-05-2012, 01:10 PM
  5. run time error 9 : subscript out of range
    By baxtercavendish in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 08-28-2009, 11:14 AM
  6. [SOLVED] run-time error '9': Subscript out of range
    By AccessHelp in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-30-2005, 01: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