+ Reply to Thread
Results 1 to 5 of 5

Redim Preserve array: subscript out of range

  1. #1
    Registered User
    Join Date
    02-05-2011
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    56

    Redim Preserve array: subscript out of range

    Hi all,

    For checking the answer to a multiple choice quiz, I wrote a subroutine. See below.
    (Undefined variables and FaultArray() are defined as Public at the top of the module.)
    What's supposed to happen is that whenever a wrong answer is given, FaultArray (a 2D array, 3 elements wide) gets a new line.
    On this line will be written
    1) the question that was asked
    2) the answer that the user gave
    3) the correct anser
    So that I can present the answers to the wrong questions after the quiz.

    Problem is: the second time the sub processes a wrong answer, I get a 'subscript out of range' error.
    Am I overlooking something? I'm stomped

    Please Login or Register  to view this content.
    quiz v10b.xlsm

  2. #2
    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: Redim Preserve array: subscript out of range

    You can only change the last dimension of a dynamic array when you use Preserve. See Help for ReDim.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Redim Preserve array: subscript out of range

    If you include the Preserve keyword, Visual Basic copies the elements from the existing array to the new array. When you use Preserve, you can resize only the last dimension of the array, and for every other dimension you must specify the same size it already has in the existing array.
    If solved remember to mark Thread as solved

  4. #4
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Redim Preserve array: subscript out of range

    something like this

    Please Login or Register  to view this content.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  5. #5
    Registered User
    Join Date
    02-05-2011
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    56

    Re: Redim Preserve array: subscript out of range

    Ah! Excellent, that clears it up. Thanks Mike for your suggestion.

+ 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