+ Reply to Thread
Results 1 to 13 of 13

Run Time Error : Subscript out of range 9

  1. #1
    Registered User
    Join Date
    07-10-2014
    Location
    India
    MS-Off Ver
    2013
    Posts
    33

    Run Time Error : Subscript out of range 9

    I have three sheets in My workbook and one user form. based on selection of checkbox in userform, I want to activate the respective sheets. While clicking on add button, I am getting error message " Run Time Error : Subscript out of range 9". I am using following code


    Please Login or Register  to view this content.
    I am getting error on "Set ws = Sheets(ID)" line. I am not exper in VBA so i am not bale to make it out. I need help on this.

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

    Re: Run Time Error : Subscript out of range 9

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    07-10-2014
    Location
    India
    MS-Off Ver
    2013
    Posts
    33

    Re: Run Time Error : Subscript out of range 9

    Many thanks for your solution. But the error is still the same. The value of "ID" on hovering mouse while debugging is coming out to be "ID = Check B" which is not expected.

    Thanks

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

    Re: Run Time Error : Subscript out of range 9

    ID = Left(cb.name,6))
    Set ws = Sheets(ID)

    You should have either a sheet named "ID" or if you are going to assign the string to sheet name, the sheet name first name to be created.

    Please Login or Register  to view this content.
    Last edited by AB33; 07-17-2014 at 02:39 AM.

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

    Re: Run Time Error : Subscript out of range 9

    Just to give you an example.

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    07-10-2014
    Location
    India
    MS-Off Ver
    2013
    Posts
    33

    Re: Run Time Error : Subscript out of range 9

    Hello ,

    I have sheets named like IN0301, IN0302,IN0304 etc. I want to activate sheet based on selection of checkbox on userform. So I have defined ID as string and passing name to ID via
    Please Login or Register  to view this content.
    and then activating sheet based on value of ID in
    Please Login or Register  to view this content.
    .

    I have attached sample workbook.

    Thanks
    Attached Files Attached Files

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

    Re: Run Time Error : Subscript out of range 9

    Please Login or Register  to view this content.
    Last edited by AB33; 07-17-2014 at 02:56 AM.

  8. #8
    Registered User
    Join Date
    07-10-2014
    Location
    India
    MS-Off Ver
    2013
    Posts
    33

    Re: Run Time Error : Subscript out of range 9

    Hello Guru,

    Many thanks for code. First It created sheet with the name of "CheckB" and then added data to first sheet irrespective of checkbox selected on userofrm.

    Thanks

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

    Re: Run Time Error : Subscript out of range 9

    The code looks at ID = Left(cb.Name, 6) and creates a new sheet based on ID and re-name the sheet name as Left(cb.Name, 6) . If the sheet name has already existed on the sheet collections, it skips the process, i.e. there is no need to re-create it as duplicate sheet names are not permitted in excel.
    The reason for getting error 9 was you were to try to access a sheet name which does not exist on sheet collection. That is "Out of script error" means.

  10. #10
    Registered User
    Join Date
    07-10-2014
    Location
    India
    MS-Off Ver
    2013
    Posts
    33

    Re: Run Time Error : Subscript out of range 9

    Dear AB33,

    I got your point. But my point is If I have selected "IN0302" checkbox on userform and this sheet already exists, so the value from combobox should go to sheet with name of IN0302. But all the data is going to IN0304.

    Many thanks

  11. #11
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Run Time Error : Subscript out of range 9

    Hi, excel_126,

    Your post does not comply with Rule 8 of our Forum RULES. Do not crosspost your question on multiple forums without including links here to the other threads on other forums.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).

    http://www.ozgrid.com/forum/showthread.php?t=189680
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  12. #12
    Registered User
    Join Date
    07-10-2014
    Location
    India
    MS-Off Ver
    2013
    Posts
    33

    Re: Run Time Error : Subscript out of range 9 (http://www.ozgrid.com/forum/showthread.php?

    Hello,

    I changed the code a litttle bit but the sheet didn't get activated based on selection of checkbox. The code is
    Please Login or Register  to view this content.
    Many Thanks
    Last edited by excel_126; 07-17-2014 at 04:08 AM.

  13. #13
    Registered User
    Join Date
    07-10-2014
    Location
    India
    MS-Off Ver
    2013
    Posts
    33

    Subscript out of range 9 http://www.ozgrid.com/forum/showthread.php?t=189680&page=2


+ 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 amber_skanpur in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 04-04-2014, 12:31 PM
  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. [SOLVED] subscript out of Range (Run time error 9), need help
    By shiva_reshs in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-05-2013, 02:31 PM
  4. run time error 9, subscript out of range
    By Nasir.Munir@dal.ca in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-06-2006, 09:31 PM
  5. run-time error '9': Subscript out of range
    By jerredjohnson in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-08-2006, 03:15 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