+ Reply to Thread
Results 1 to 4 of 4

dynamic array redim preserve: run-time error 9, Subscript out of range.

  1. #1
    Registered User
    Join Date
    07-20-2009
    Location
    Norway
    MS-Off Ver
    Excel 2003
    Posts
    4

    dynamic array redim preserve: run-time error 9, Subscript out of range.

    Hi!

    I found quite a few posts about this problem, but none of the answers was any use to me...

    I need to redimension a 2 dimensional array in a Sub. I deleted all the code that is not of interest:

    Please Login or Register  to view this content.


    Can somebody tell my why I receive the Run-time error '9': Subscript out of range"?.... or even better, tell me how to avoid it?

    Thanks in advance!

    Broesel
    Last edited by Broesel; 07-21-2009 at 07:15 AM.

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

    Re: dynamic array redim preserve: run-time error 9, Subscript out of range.

    If you use Preserve, you can only change the last dimension of the array.
    Remember what the dormouse said
    Feed your head

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: dynamic array redim preserve: run-time error 9, Subscript out of range.

    The help on Redim states.

    If you use the Preserve keyword, you can resize only the last array dimension and you can't change the number of dimensions at all. For example, if your array has only one dimension, you can resize that dimension because it is the last and only dimension. However, if your array has two or more dimensions, you can change the size of only the last dimension and still preserve the contents of the array. The following example shows how you can increase the size of the last dimension of a dynamic array without erasing any existing data contained in the array.
    You will need to swap in dimensions
    Cheers
    Andy
    www.andypope.info

  4. #4
    Registered User
    Join Date
    07-20-2009
    Location
    Norway
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: dynamic array redim preserve: run-time error 9, Subscript out of range.

    Ah, now we're talking!

    That's what I just did: Swapped the dimensions!

    Thank you very much, both of you!

    Broesel

+ 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