Results 1 to 3 of 3

Subscript out of range error using all possible combinations code

Threaded View

  1. #1
    Registered User
    Join Date
    05-05-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    2

    Subscript out of range error using all possible combinations code

    I have this code:
    Sub test()
    
    Dim i As Long
    
    Dim t As Long
    Dim f As Long
    Dim m As Long
    Dim l As Long
    Dim c As Long
    
    lCombinations = (UBound(Track) + 1) * (UBound(Financials) + 1) * _
    (UBound(Management) + 1) * (UBound(Liquidity) + 1) * (UBound(Industry) + 1) * (UBound(Security) + 1)
    
    ReDim arrResult(1 To lCombinations, 1 To 6)
    
    For t = 0 To 5
    For f = 0 To 5
    For m = 0 To 5
    For l = 0 To 5
    For c = 0 To 5
    For s = 0 To 5
    
    i = i + 1
    
    arrResult(i, 1) = Track(t)
    arrResult(i, 2) = Financials(f)
    arrResult(i, 3) = Management(m)
    arrResult(i, 4) = Liquidity(l)
    arrResult(i, 5) = Industry(c)
    arrResult(i, 6) = Security(s)
    Debug.Print Security(s)
    
    Next s
    Next c
    Next l
    Next m
    Next f
    Next t
    
    'to test the array
    Range(Cells(1), Cells(lCombinations, 6)) = arrResult
    
    End Sub

    And it works fine through the first 5 iterations of the i+1 loop, but when it comes to "Next C" I get an error that says subscript out of range. Any ideas why this may be happening?

    Any help would be greatly appreciated.
    Cheers,
    Ali
    Last edited by alisalamiii; 05-05-2010 at 11:59 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