+ Reply to Thread
Results 1 to 25 of 25

getting Error 9 "Subscript out of range" with code

  1. #1
    Forum Contributor
    Join Date
    12-02-2013
    Location
    Melbourne,Australia
    MS-Off Ver
    Excel 2010
    Posts
    101

    getting Error 9 "Subscript out of range" with code

    I get an error when trying to transfer data using userform.When selecting from userform the date,team & shift and items (1,2 or 3 items) from Listbox1 i get an error.If say I select day then I only need info from day transferred but if I select "all" from dropdown box I need all 3 shifts info transferred for that selected date

    Any help appreciated

    H
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,963

    re: getting Error 9 "Suncsript out of rnage" with code

    You cannot do:
    Please Login or Register  to view this content.
    You need a loop something like below:
    Please Login or Register  to view this content.
    Last edited by protonLeah; 12-23-2013 at 01:28 AM.
    Ben Van Johnson

  3. #3
    Forum Contributor
    Join Date
    12-02-2013
    Location
    Melbourne,Australia
    MS-Off Ver
    Excel 2010
    Posts
    101

    re: getting Error 9 "Suncsript out of rnage" with code

    Thanks

    I still get an error

    Thanks
    Attached Files Attached Files

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,963

    re: getting Error 9 "Suncsript out of rnage" with code

    You have spaces at the end of some of the names on the sheets themselves.

  5. #5
    Forum Contributor
    Join Date
    12-02-2013
    Location
    Melbourne,Australia
    MS-Off Ver
    Excel 2010
    Posts
    101

    re: getting Error 9 "Suncsript out of rnage" with code

    Thanks

    I have this error now

    Please Login or Register  to view this content.

  6. #6
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,963

    re: getting Error 9 "Suncsript out of rnage" with code

    In my original post, I moved: Set wksDest = ThisWorkbook.Worksheets("group a") outside of the For Each... loop. It's missing from your current code altogether. I have edited post #2 in RED.

  7. #7
    Forum Contributor
    Join Date
    12-02-2013
    Location
    Melbourne,Australia
    MS-Off Ver
    Excel 2010
    Posts
    101

    re: getting Error 9 "Suncsript out of rnage" with code

    Thanks

    It does place the data now but still gives an error...also it does not differentiate between Day, Afternoon Night when selecting from userform..

    Thanks

  8. #8
    Forum Contributor
    Join Date
    12-02-2013
    Location
    Melbourne,Australia
    MS-Off Ver
    Excel 2010
    Posts
    101

    re: getting Error 9 "Suncsript out of rnage" with code

    Hi

    The error is a - code 9 Subscript out of Range....error in code below from attached workbook post #7
    Please Login or Register  to view this content.
    The sheets are in the workbook but could this be from the Array or Loop

    Thanks

  9. #9
    Forum Contributor
    Join Date
    12-02-2013
    Location
    Melbourne,Australia
    MS-Off Ver
    Excel 2010
    Posts
    101

    re: getting Error 9 "Suncsript out of rnage" with code

    Still having issues .. could this be a potential issue

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  10. #10
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,963

    re: getting Error 9 "Suncsript out of rnage" with code

    Sorry I haven't had chance to look at this today. I'll try tomorrow, but it may be Thursday.

  11. #11
    Forum Contributor
    Join Date
    12-02-2013
    Location
    Melbourne,Australia
    MS-Off Ver
    Excel 2010
    Posts
    101

    re: getting Error 9 "Suncsript out of rnage" with code

    Thank you

    It seems to be the counter I think

    Please Login or Register  to view this content.
    Combobox2 -- I am hoping to also have it show for the selected date either just data for Day or Afternoon or Night or if "All" selected transfer for all 3 shifts....

    Thanks again
    Attached Files Attached Files

  12. #12
    Forum Contributor
    Join Date
    12-02-2013
    Location
    Melbourne,Australia
    MS-Off Ver
    Excel 2010
    Posts
    101

    re: getting Error 9 "Suncsript out of rnage" with code

    Hi

    I made some changes but still there is miss-alignment,,,any thoughts please

    Also when I delete it removes the headings

    This should read...I notices after I posted the file
    Please Login or Register  to view this content.

    Thanks
    Last edited by H_Kennedy; 12-26-2013 at 07:56 PM.

  13. #13
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,963

    Re: getting error with code

    Please test the attachment. I made some changes. I deleted the For Each loop. Since you specify which team you want to process it's not necessary. I added code to only check specified stops if "All" is not selected. I tried to test for errors but...
    Attached Files Attached Files

  14. #14
    Forum Contributor
    Join Date
    12-02-2013
    Location
    Melbourne,Australia
    MS-Off Ver
    Excel 2010
    Posts
    101

    Re: getting Error 9 "Subscript out of range" with code

    Thank you

    When I delete the data and re-enter data from userform this errors

    Please Login or Register  to view this content.
    Then I stop the debugger and it works again but it is missing the Shift for Internal and Excternal

    Thank you

  15. #15
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,963

    Re: getting Error 9 "Subscript out of range" with code

    What Team, date, etc. did you choose that caused the error? I've been trying to guess.

  16. #16
    Forum Contributor
    Join Date
    12-02-2013
    Location
    Melbourne,Australia
    MS-Off Ver
    Excel 2010
    Posts
    101

    Re: getting Error 9 "Subscript out of range" with code

    Team A and 15-dec-2013
    Thanks

  17. #17
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,963

    Re: getting Error 9 "Subscript out of range" with code

    The following works as long as there are no more than six total items per stop, because your arrays are dimensioned with six rows and your report form only allows for six items per stop. So if a counter increments to 7 you will get a "subscript out of range" error.
    Attached Files Attached Files

  18. #18
    Forum Contributor
    Join Date
    12-02-2013
    Location
    Melbourne,Australia
    MS-Off Ver
    Excel 2010
    Posts
    101

    Re: getting Error 9 "Subscript out of range" with code

    Thank you
    That works really well.

    If I insert another 4 rows for each stop (10 for each Stop instead of 6) is this possible to change in the code?
    In the future there may be a need to add more rows so if it is possible where can I change the code?

    Thanks for your help

  19. #19
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,963

    Re: getting Error 9 "Subscript out of range" with code

    The simplest way would be to add the four new rows to each STOP block, then hard code the changes.

    Change the dimensions of the arrays from arrOP_PS(1 To 6, 1 To 5) to arrOP_PS(1 To 10, 1 To 5), etc.

    WksDest.Range("O6") would stay the same, but,
    WksDest.Range("O15") would change to "O19"
    and WksDest.Range("O24") would change to "O28"

  20. #20
    Forum Contributor
    Join Date
    12-02-2013
    Location
    Melbourne,Australia
    MS-Off Ver
    Excel 2010
    Posts
    101

    Re: getting Error 9 "Subscript out of range" with code

    Thanks ProtonLeah

    All the changes now work..thanks

    I have a final question please

    I am going to transfer all 3 shifts everytime so will not need the option for selecting Day,Afternoon or Night......all 3 will be transferred everytime
    I am also going to transfer all 3 stops everytime so will not need to select individually Planned Stops,Unplanned Internal and External.....all 3 stops transferred everytime

    In the Userform I will only need the Date and selection of a Team plus Transfer button.....does the code need to be altered or do I just remove the Stop Type Listbox and Shift Combobox from the Userform or can the code be commented out for future use if required?

    I just want to remove the option for selecting a particular shift and also a particular stop....all will be transferred everytime

    Thanks
    Attached Files Attached Files

  21. #21
    Forum Contributor
    Join Date
    12-02-2013
    Location
    Melbourne,Australia
    MS-Off Ver
    Excel 2010
    Posts
    101

    Re: getting Error 9 "Subscript out of range" with code

    Hi

    I have a final question please

    I am going to transfer all 3 shifts everytime so will not need the option for selecting Day,Afternoon or Night......all 3 will be transferred everytime
    I am also going to transfer all 3 stops everytime so will not need to select individually Planned Stops,Unplanned Internal and External.....all 3 stops transferred everytime

    In the Userform I will only need the Date and selection of a Team plus Transfer button.....does the code need to be altered or do I just remove the Stop Type Listbox and Shift Combobox from the Userform or can the code be commented out for future use if required?

    I just want to remove the option for selecting a particular shift and also a particular stop....all will be transferred everytime

    Thanks
    Last edited by H_Kennedy; 01-03-2014 at 02:45 AM.

  22. #22
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,963

    Re: getting Error 9 "Subscript out of range" with code

    Try this one. The design of the form is the same but I set the shift and stop boxes to hidden and modified the code to ignore
    Attached Files Attached Files

  23. #23
    Forum Contributor
    Join Date
    12-02-2013
    Location
    Melbourne,Australia
    MS-Off Ver
    Excel 2010
    Posts
    101

    Re: getting Error 9 "Subscript out of range" with code

    Thanks once again

    That works nicely...to finish this workbook off can the actual Shift and Stop box`s be removed completely from the Userform so I can redesign and make the Userform smaller with only the Date and Team Box`s...I removed but it gave an error

    Thanks for all the help

  24. #24
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,963

    Re: getting Error 9 "Subscript out of range" with code

    Yes. Just select and delete them. Then delete the commented out code that references them.

  25. #25
    Forum Contributor
    Join Date
    12-02-2013
    Location
    Melbourne,Australia
    MS-Off Ver
    Excel 2010
    Posts
    101

    Re: getting Error 9 "Subscript out of range" with code

    Hi ProtonLeah

    Thanks for the help...appreciated

+ 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 "Subscript out of range", cant seem to find where code is wrong
    By KeithMale in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-14-2013, 07:07 PM
  2. [SOLVED] trying to understand why a code is not working "error 9 subscript out off range"
    By cdafonseca in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-09-2013, 12:33 PM
  3. [SOLVED] Can't debug this code. The Arrays are producing a Subscript out of Range error
    By seigna in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-06-2013, 05:14 PM
  4. Subscript out of range error & code not working
    By HP RodNuclear in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 07-01-2011, 03:53 PM
  5. Subscript out of range error using all possible combinations code
    By alisalamiii in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-05-2010, 09:57 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