+ Reply to Thread
Results 1 to 5 of 5

Array size limits in Resize Transpose code

Hybrid View

  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.

  2. #2
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628

    Re: Array size limits in Resize Transpose code

    Your problem is due to the number of rows in Excel 2003 which is 65536 rows. You should use Excel 2007.2010 or use multiple columns, eg. GH, IJ, and then so on to bring out all the necessary data.
    If you like the solution of multiple columns macro can be easily modified.

    Regards,
    Antonio

  3. #3
    Registered User
    Join Date
    04-24-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    43

    Re: Array size limits in Resize Transpose code

    Thanks Antonio, I've had a think and for me the most computationally efficient work around would be to modify the step:

    For i = 1 To n - 1 Step 2 'or 3 or 4 or 5 etc....
    By adding in this step the macro can skip some of the non zero numbers. This for me is fine as the data are being compiled to extract key trends, and there will still be plenty of data for the trends to be unaffected by this sub-sampling approach

  4. #4
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Array size limits in Resize Transpose code

    hi, carbonboywonder, basing on your example I do not understand what limitations you are talking about if your result data is returned in column. It has the only limit of number of rows of the Excel sheet: 65536 for Excel 2003 or over 1 million for Excel 2007. As soon as your original data is within the sheet limits the code will process data without any problems.
    Re: Error 13 Type Mismatch - most probably it is caused by non-digit value in array that is for example divided by number.

    PS. The code uses not the best methods in terms of its efficiency - Preserve is rather costly thing to use. I'm PC user.
    Last edited by watersev; 03-14-2011 at 09:15 AM.

  5. #5
    Registered User
    Join Date
    04-24-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    43

    Re: Array size limits in Resize Transpose code

    Thanks watersev. There's no problem with the arrays themselves, but I agree about efficiency. This for me is not a big deal though, as long as it works I'm happy. I have marked this solved now as I'm happy with my step workaround to fit the data onto a sheet

+ 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