+ Reply to Thread
Results 1 to 10 of 10

Subscript out of range

  1. #1
    Registered User
    Join Date
    06-01-2009
    Location
    chicago
    MS-Off Ver
    Excel 2007
    Posts
    4

    Subscript out of range

    All:

    I'm new to VBA, however I'm an experienced programmer. I'm running the following routine:

    Please Login or Register  to view this content.
    The bolded line gives the subscript out of line error. As an additional debug step, I tried declaring another random variable called test2 (variant) and the line test2 = test(i) also returns this error.

    This is very puzzling to me, as the LBound and UBound of test (as determined by stepping through the code) are 1 and 66 returned, yet this is crashing out on the first iteration of the loop when i=1!!!

    Does anyone have any insight in to this whatsoever?! I have burned a whole day on this with no progress, and I would really appreciate any help.

    Thanks in advance, mcukier
    Last edited by mcukier; 06-02-2009 at 10:09 AM.

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

    re: Subscript out of range

    Please take a few minutes to read the forum rules, and then edit your post to add code tags.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    06-01-2009
    Location
    chicago
    MS-Off Ver
    Excel 2007
    Posts
    4

    re: Subscript out of range

    oops, sorry about that -- edit complete.

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

    re: Subscript out of range

    Assuming LBound is zero, what cell are you storing data in, in the first iteration of the loop?

  5. #5
    Forum Contributor starryknight64's Avatar
    Join Date
    09-27-2006
    Location
    Missouri
    MS-Off Ver
    2003 (Work) & 2007 (Home)
    Posts
    193

    re: Subscript out of range

    Yeah, it looks to me like you're trying to access row zero (doesn't exist).

    Try the following instead:

    Please Login or Register  to view this content.
    starryknight64

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

    re: Subscript out of range

    Or
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    06-01-2009
    Location
    chicago
    MS-Off Ver
    Excel 2007
    Posts
    4

    re: Subscript out of range

    Hey Guys:

    Thanks for the responses. On the first iteration of the loop, i is 1 because LBound is 1. I have verified this with variable watch, and mouseover. As an additional debug step, I verified that I get the same error with the bolded line below inserted within the for loop rather than the line that referenced the cells:

    Please Login or Register  to view this content.
    I still get the same error, which is clearly indicating that the test(i) reference is generating the error. (also, during debug I can simply mouseover that part of the statement, and the tooltip says test(i) = subscript out of range, or something along those lines)

    And, if I link to this DDE object through the GUI, it works and does in fact populate all 66 rows with the appropriate formula (I paste the DDE formula in the first row, then highlight 66 rows in that column, hit F2, then ctrl + shift + enter, and all the DDE forumulas appear as expected). However, for my application, that method won't work as I need to be able to change the DDE request based on the information in a given cell....

    Like I said... I'm absolutely baffled!!

    SIDENOTE: the application I'm working with does NOT have a well defined (or printed out) DDE protocol... so I have no way of actually knowing what data is being returned to me. It seems to me that it's a 1x66 array of numbers.... judging from my experience within the excel GUI. Not sure if this is relevant or not.

    Thanks, mcukier
    Last edited by mcukier; 06-01-2009 at 05:33 PM.

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

    re: Subscript out of range

    Look at test in the Watch window -- is it two-dimensional?

  9. #9
    Registered User
    Join Date
    06-01-2009
    Location
    chicago
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Subscript out of range

    shg --

    EXCELLENT call!! As it turned out, I was being returned a two dimensional array (which, quite frankly, is ridiculous... since the second dimension's range is 1 to 1).

    So, once I reference both dimensions (eg, test(i, 1) ) the code proceeds with no errors!

    Thanks so much for everyone's input.

    Regards,
    Mark

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

    Re: Subscript out of range

    You're welcome. Would you please mark the thread as Solved?

+ 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