+ Reply to Thread
Results 1 to 21 of 21

run time error 9 : subscript out of range

  1. #1
    Registered User
    Join Date
    08-20-2009
    Location
    NC
    MS-Off Ver
    Excel 2000
    Posts
    21

    run time error 9 : subscript out of range

    This program is supposed to take the value in two combo boxes and use them to populate pivot charts that are in other spreadsheets. So a user would select PS and AMI on sheet one (s) and it would change the pivot table on s1-s9 to look up those chosen fields. I keep getting a subscript out of range error, and I'm not sure if my pivottable.pivotlayout method is correct, but when I recorded a macro (in the very bottom) using activesheet, it worked. How can I fix this?

    The error occurs at the first large text, the second large text is the recorded macro.

    Please Login or Register  to view this content.

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: run time error 9 : subscript out of range

    That would imply that either the workbook name or worksheet name are incorrect.
    Remember what the dormouse said
    Feed your head

  3. #3
    Registered User
    Join Date
    08-20-2009
    Location
    NC
    MS-Off Ver
    Excel 2000
    Posts
    21

    Re: run time error 9 : subscript out of range

    I have checked that, its not the case. I copied the names of the tabs directly from the sheet tabs, and then also copied the workbook name directly. No fix.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: run time error 9 : subscript out of range

    Or the workbook is not open.

    That about rounds out the possibilities.
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Registered User
    Join Date
    08-20-2009
    Location
    NC
    MS-Off Ver
    Excel 2000
    Posts
    21

    Re: run time error 9 : subscript out of range

    i'm sure this is about to make me look like an idiot

    all the sheets are in the same file, do I need to reference the workbook?

    I'm an idiot, right?

    I should also say this is only the third code I have made.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: run time error 9 : subscript out of range

    You need to if it's not the activeworkbook, but it's better practice to provide the complete reference in any case.

  7. #7
    Registered User
    Join Date
    08-20-2009
    Location
    NC
    MS-Off Ver
    Excel 2000
    Posts
    21

    Re: run time error 9 : subscript out of range

    All the sheets are in the leading indicators fw33.xls workbook. But I want this all to run in the background so that if the button is pressed, you dont see every sheet pop up as it updates.

    do I say this:
    Please Login or Register  to view this content.
    Then what should the beginning of this line look like?

    Please Login or Register  to view this content.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: run time error 9 : subscript out of range

    Please Login or Register  to view this content.
    That's not correct, because ws is a worksheet object, not a workbook object.

  9. #9
    Registered User
    Join Date
    08-20-2009
    Location
    NC
    MS-Off Ver
    Excel 2000
    Posts
    21

    Re: run time error 9 : subscript out of range

    okay, I'm not quite sure what you mean. This worked on a previous macro I wrote, so I don't quite understand the difference

    do i declare
    Please Login or Register  to view this content.

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: run time error 9 : subscript out of range

    I don't use pivot tables (gasp), but the rest of it looks fine, except you can't have a bracket in a sheet name:
    Please Login or Register  to view this content.

  11. #11
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: run time error 9 : subscript out of range

    Quote Originally Posted by baxtercavendish View Post
    Please Login or Register  to view this content.
    That won't work. You need to declare the two variables as worksheet since you are trying to return Worksheet objects.
    On that note, is one of your sheets perhaps a chart sheet and not a worksheet?

  12. #12
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: run time error 9 : subscript out of range

    Argh, I missed that you changed that, sorry.

  13. #13
    Registered User
    Join Date
    08-20-2009
    Location
    NC
    MS-Off Ver
    Excel 2000
    Posts
    21

    Re: run time error 9 : subscript out of range

    the opportunity created sheet is just a pivot chart, I got this file from my boss. I guess that would just make it a chart sheet.

  14. #14
    Registered User
    Join Date
    08-20-2009
    Location
    NC
    MS-Off Ver
    Excel 2000
    Posts
    21

    Re: run time error 9 : subscript out of range

    does that have a different name for the code?

  15. #15
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: run time error 9 : subscript out of range

    Yes:
    Please Login or Register  to view this content.

  16. #16
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: run time error 9 : subscript out of range

    Note that you also cannot then refer to a PivotTable on that sheet, since there isn't one. You need to refer to the sheet that contains the table the chart is linked to.

  17. #17
    Registered User
    Join Date
    08-20-2009
    Location
    NC
    MS-Off Ver
    Excel 2000
    Posts
    21

    Re: run time error 9 : subscript out of range

    Please Login or Register  to view this content.
    so on the next lines, should I change ws1 to .charts(cht)?
    should it be cht.pivottables ... ? I'm getting an object doesnt support property or method on the pivot tables line.

    Please Login or Register  to view this content.

    This code is causing me a lot of grief.

  18. #18
    Registered User
    Join Date
    08-20-2009
    Location
    NC
    MS-Off Ver
    Excel 2000
    Posts
    21

    Re: run time error 9 : subscript out of range

    Unable to set the _Default property of the PivotItem class
    Please Login or Register  to view this content.
    I appreciate everyones help, but do realize, I'm new to coding so I don't really understand all the advice that is being given.

  19. #19
    Registered User
    Join Date
    08-20-2009
    Location
    NC
    MS-Off Ver
    Excel 2000
    Posts
    21

    Re: run time error 9 : subscript out of range

    Okay, instead of trying to update the chart, can I not just update the sheet that has the pivot table instead? So I set Combobox 1 and 2 on the first sheet, then have the pivot table in "sheet1" change. Here is the recorded macro

    Please Login or Register  to view this content.
    and here is what I tried:

    Please Login or Register  to view this content.
    I get run time error 1004: unable to set the default property of the pivotitem class at the bolded line.

  20. #20
    Registered User
    Join Date
    08-20-2009
    Location
    NC
    MS-Off Ver
    Excel 2000
    Posts
    21

    Re: run time error 9 : subscript out of range

    I also tried this code, I found searching the net; I get a run time error 424 : object required, then the highlighted field says "method range of objects '_worksheet failed when hovered over it.

    To be honest I'd like to use something simple like the code I put in the previous post above this.

    Please Login or Register  to view this content.

  21. #21
    Registered User
    Join Date
    08-20-2009
    Location
    NC
    MS-Off Ver
    Excel 2000
    Posts
    21

    Re: run time error 9 : subscript out of range

    actually i think i fixed it guys, sorry for all the posts

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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