Results 1 to 4 of 4

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

Threaded View

  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:

    Option Explicit 
    Dim Gear() As String                   'I also tried "Private" and without the "As String", or givin a specific dimension right here.
    
    Sub Workbook_Open()
    Call setup_arrays
    
    If Gear(i, 1) = "son-and so" Then 
       [blablabla]
    End If 
    End Sub
    
    
    
    
    Sub setup_arrays()
    
    ReDim Gear(8, 2) As String        ' I also tried "Redim Preserve"
        Gear(1, 1) = "a"
        Gear(2, 1) = "b"
        [...]
        Gear(8, 1) = "c"
    
    Do While temp = "6"                  ' this is of course true, when testing...
        MsgBox "the code works fine until here!!!"
        ReDim Preserve Gear(UBound(Gear) + 1, 2) As String                  ' this code causes the error! All I want is to increase the first dimension of the array by 1, while the second dimension remains untouched.
        Gear(UBound(Gear), 1) = "d"
    Loop
    
    [...]
    
    End Sub


    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.

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