+ Reply to Thread
Results 1 to 4 of 4

Loop variable subscript out of range

  1. #1
    Registered User
    Join Date
    06-01-2015
    Location
    Netherlands
    MS-Off Ver
    2010
    Posts
    2

    Loop variable subscript out of range

    I can't discover what is wrong in my code.
    ArraySeasonality(M) is constantly saying that the subscript is out of range, yet I let M (it was I before but I tried a different variable, still didn't work) loop from 0 to 3 and ArraySeasonality has 4 datapoints (0,1,2,3)
    It is probably something I do wrong in the way I write the loops. When I remove the I=0 lines then the other variables show the subscript out of range as well.

    Please Login or Register  to view this content.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Loop variable subscript out of range

    Hi, and welcome to the forum.

    It would have been more useful if you had uploaded the workbook so that we can see the problem in context.

    However I suspect it's probably because you have only dimmed the array as 3 despite you saying there are 4 values - and I can see no Redim instruction.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    06-01-2015
    Location
    Netherlands
    MS-Off Ver
    2010
    Posts
    2

    Re: Loop variable subscript out of range

    Thank you for your reaction.
    However that can't be the problem can it? An array of 3 by default has 4 values? (0,1,2,3)
    Anyway I fixed the problem by just changing all the if statements to do while statements, still a bit weird.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Loop variable subscript out of range

    Hi,

    Depends on whether the Base is zero or one.

+ 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. Help reading For loop with range variable
    By Maradona_10 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-28-2014, 02:49 PM
  2. Do Loop with variable range
    By Austex_egger in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 08-08-2013, 03:08 PM
  3. Do Loop with Variable Range
    By Austex_egger in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-24-2013, 03:52 PM
  4. [SOLVED] Select Sheets based on variable array -ERROR 9 Subscript out of range
    By airmiles in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-19-2012, 07:28 PM
  5. Why did an inner loop variable start overwriting the outer loop range suddenly?
    By 111StepsAhead in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-16-2012, 03:24 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