Results 1 to 5 of 5

Array size limits in Resize Transpose code

Threaded View

carbonboywonder Array size limits in Resize... 03-14-2011, 06:06 AM
antoka05 Re: Array size limits in... 03-14-2011, 07:20 AM
carbonboywonder Re: Array size limits in... 03-14-2011, 09:08 AM
watersev Re: Array size limits in... 03-14-2011, 09:12 AM
carbonboywonder Re: Array size limits in... 03-14-2011, 09:19 AM
  1. #1
    Registered User
    Join Date
    04-24-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    43

    Array size limits in Resize Transpose code

    Hi all, I've got an issue regarding array size limits in Excel, which I thought was solved but unfortunately persists:

    --Background--
    I have the following bit of code that performs an averaging function between pairs of non-zero numbers in an array. It outputs the average value based on the number of rows that the cells were apart. Running the macro returns a column of these averages, together with a column giving the number of rows over which the average was calculated. You can see this in action in the attached file.

    --Problem--
    The problem I have is that I get a 'run-time error "13"' Type Mismatch when I run the code on my Mac and there are more than 91 non zero values in my array. Thanks to members of this forum, I have since discovered that the number of non zero numbers can be up to about 350 if the code is run on a PC rather than a Mac. I have since realised though that some of the arrays I have contain >1000 non zero numbers, hence the problem remains

    Basically therefore, I need a way of telling the code to stop once this limit of 350 is reached. I'm not sure exactly how to implement this so any help would be gratefully appreciated

    The attached file should help illustrate the problem

    Sub x()
    
    Dim vData As Variant, n As Long, r As Long, vOut(), i As Long
    Dim vOut2(), vOut3(), j As Long, k As Long, p As Double
    
    Application.ScreenUpdating = False
    
    vData = Range("A2", Range("A2").End(xlDown)).Value
    ReDim vOut(1 To UBound(vData, 1), 1 To 2)
    
    For r = 1 To UBound(vData, 1)
        If vData(r, 1) > 0 Then
            n = n + 1
            vOut(n, 1) = vData(r, 1)
            vOut(n, 2) = r
        End If
    Next r
    
    For i = 1 To n - 1
        p = vOut(i, 1)
        For j = i + 1 To n
            k = k + 1
            p = p + vOut(j, 1)
            ReDim Preserve vOut2(1 To k)
            ReDim Preserve vOut3(1 To k)
            vOut2(k) = vOut(j, 2) - vOut(i, 2)
            vOut3(k) = p / (vOut2(k) + 1)
        Next j
    Next i
    
    Range("C2").Resize(k) = Application.Transpose(vOut2)
    Range("D2").Resize(k) = Application.Transpose(vOut3)
    
       Range("C2:D2").Select
             Range(Selection, Selection.End(xlDown)).Select
                Selection.Copy
        Range("G65536").End(xlUp).Offset(1, 0).Select
            Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
                False, Transpose:=False
    Columns("C:D").Clear
    
    End Sub
    Attached Files Attached Files
    Last edited by carbonboywonder; 03-14-2011 at 09:20 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