+ Reply to Thread
Results 1 to 32 of 32

Subscript out of Range error

  1. #1
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Subscript out of Range error

    In the attached workbook I am getting a "SUBSCRIPT OUT OF RANGE" error on the following line.

    Please Login or Register  to view this content.
    The data is present in 'ref' however, the variant clears out at some point with no explanation. Here is complete code as well.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by lloydgodin; 03-06-2013 at 12:06 PM. Reason: corrected attachment

  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

    I get a Select method of range... error not subscript out of range.

    If I change the loop to this, no error...
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Subscript out of Range error

    I am not even getting the error anymore. I'm not sure why or where...

    And here is the corrected attachment.
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Subscript out of Range error

    And now I AM getting the same error that you did.
    When I changed to your code I get the SUBSCRIPT OUT OF RANGE error again.

  5. #5
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Subscript out of Range error

    Since 'ref' is contained in an add-in I thought the section of code causing the problem might be this:

    Please Login or Register  to view this content.
    Other sections that reference it work.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645
    Did you try the change I suggested?

  7. #7
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Subscript out of Range error

    Yes. And I get the subscipt out of range error still.

  8. #8
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Subscript out of Range error

    The add-in cannot be attached but it is a file that contains the above code in a module, the tab REF and the following code in ThisWorkbook:

    Please Login or Register  to view this content.

  9. #9
    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

    It probably is some sort of reference problem that's causing the error(s).

    Hard to tell/test though without the add-in.

  10. #10
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Subscript out of Range error

    The site wont let me upload it. However, it can be created with the 11:26 post and last attachment has the "REF" tab.

  11. #11
    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

    Sorry, 11:26 post?

    Could you post it's number?

    PS Are the 2 files you uploaded different?

  12. #12
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Subscript out of Range error

    Post #8. 11:26 was the time on it b/c I didn't see the post numbers.

    The file in post #3 contains the REF tab whereas post 1 did not.

  13. #13
    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

    Post #8 was at 5:26 pm GMT.

    I'll have a look at the file later.

    You say it's an addin?

    Do you have a sample workbook to work with it, or will a blank one do?

  14. #14
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Subscript out of Range error

    Different time zones, LOL.

    Yes the ResetTest.xls is the sample workbook and using the code from previous posts and the REF tab from ResetTest you can create the add-in. It more accurately reflects how I am doing things on this end.

  15. #15
    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

    So what should I use as a sample workbook?

  16. #16
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Subscript out of Range error

    the ResetTest.xls is the sample workbook
    DOesn't matter what you put into as long as you insert lines at 13 and fill it with garbage data. And where it says FACS# put something else is.

  17. #17
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Subscript out of Range error

    Threadbump

  18. #18
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Subscript out of Range error

    I think it has to do with the variant 'n.' It's running it 101 times and after the data is empty it'll give the subscript out of range error.

  19. #19
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Subscript out of Range error

    bumping this again.

  20. #20
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Subscript out of Range error

    Hi Lloyd,

    I was playing with it too and this worked for me:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  21. #21
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Subscript out of Range error

    Thank XL. I'm actually in the office (Camarillo, CA) and the files are back in Texas on my computer. I will try it when I get back home and let you know. Thank you again.

  22. #22
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Subscript out of Range error

    You're welcome!

  23. #23
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Subscript out of Range error

    Nothing I am doing is working. So I zipped the addin, as well as an actual spreadsheet it would be used on.
    Last edited by lloydgodin; 04-10-2013 at 08:03 AM. Reason: removed attachments.

  24. #24
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Subscript out of Range error

    Hi Lloyd,

    I altered the add in code a little and it ran - see if it's good enough:

    Please Login or Register  to view this content.

  25. #25
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Subscript out of Range error

    If you could highlight the changes and explain why that would be helpful to me. It is working perfectly. Thank you.

  26. #26
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Subscript out of Range error

    Hi Lloyd,

    I noticed that it was choking when the ref was null - so I just told it to ignore null ref records:

    Please Login or Register  to view this content.
    Oh! and since the code uses the select feature for the range I Activated the Sheet.
    Last edited by xladept; 04-10-2013 at 01:31 PM.

  27. #27
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Subscript out of Range error

    OK. I can see that now. Not sure why it was returning null references though.
    Also what did the CStr() do?

    I'm pretty new to programming and hardly use what I've learned.

  28. #28
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Subscript out of Range error

    Hi Lloyd,

    That's a pretty sophisticate system for a newcomer - the CStr renders the worksheet name reference into a string and it's necessary because worksheet names are strings
    Last edited by xladept; 04-10-2013 at 09:52 PM.

  29. #29
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Subscript out of Range error

    Well I have had help from several people on here to get it to do what I want it to do.

    I did notice 1 error a week later. There are other workbooks that contain several worksheets (as opposed to the ER which contains just "emergency room"). The bill analysis clears ALL worksheets in a single workbook. Not really a problem except it only clears them and does not do the final step of putting "FACS#" into the cell and selecting the same. It only does that on the worksheet it's used on.

  30. #30
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Subscript out of Range error

    Hi LLoyd,

    Can you post the code or, even better, a sample spreadsheet with the fault??

  31. #31
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Subscript out of Range error

    I figured it out. The code you had provided went through the whole array n=lBound to uBound and used any worksheet name data contained in vData(n,2). All 100 worksheets. So I replaced

    Please Login or Register  to view this content.
    with

    Please Login or Register  to view this content.
    Where wks = Activesheet so it only runs the code if the sheet is Active which is what I needed it to do.

  32. #32
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Subscript out of Range error

    Good! - Glad you got it!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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