Out of memory Run-time 7 Transferring data

ItalianPlatinum

Well-known Member
Joined
Mar 23, 2017
Messages
857
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I am running into a runtime error trying to transfer data using VBA I used before so I know it works. But when facing a larger data set it is kicking out the below. is there any root cause / solution I can entertain?

1717504903932.png
1717504915271.png


VBA Code:
If Application.WorksheetFunction.CountIf(rng, ">1") > 0 Then

'transfer data over to Compare tab
  vCols = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17) '<- Columns of interest in specified order
  With WsSec
    With .Range("A11:R" & .Range("H" & rows.count).End(xlUp).row)
            vRows = Application.Index(.Cells, Evaluate("row(1:" & .rows.count & ")"), Array(17))
            For ii = 1 To UBound(vRows)
                If vRows(ii, 1) > "1" Then
                    kk = kk + 1
                    vRows(kk, 1) = ii
        End If
      Next ii
        nrALL = WsALL.Range("A" & rows.count).End(xlUp).row + 1
        WsALL.Range("A" & nrALL).Resize(kk, UBound(vCols) + 1).Value = Application.Index(.Cells.Value, Application.Index(vRows, 0, 1), vCols)
    End With
  End With
    End If

kk = 0
ii = 0
rng = 0
Debug.Print "CountIf Formula/delete/transfer... : " & Format(Timer - t, "0.00") & " seconds"
  
'apply filter to start and activate sheet
With WsSec
    .Application.Calculation = xlManual
    .Range("A10").CurrentRegion.Delete
End With
  
    i = i + 1
Loop

With WsALL
lr2 = .Cells(rows.count, "A").End(xlUp).row 'find the maximum row
    .Cells.EntireColumn.AutoFit
    .Range("1:1").AutoFilter
End With

Else

at this spot it fails
VBA Code:
WsALL.Range("A" & nrALL).Resize(kk, UBound(vCols) + 1).Value = Application.Index(.Cells.Value, Application.Index(vRows, 0, 1), vCols)
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Take it in chunks? AFAIK, array size limit is governed by your available pc memory.
Maybe have a For Next loop that takes n rows at a time, writes/copies data then begins again at n+1.
So if last row = 100,000 loop from 2 (?) to 10,000 and write/copy.
Then increment start position by ending value (10,000) +1; ending value by 10,000 + 10,000 (or last row value if that is smaller).
Or shell out for more memory.
 
Upvote 0
So depending on my PC memory I really don't know what the array size limit could be. Reason I ask is I would need it to run as is but then have this new procedure if there is a possibility i reach that limit? I may need help in modifying to fit that type of procedure, this way I can test out and see how it handles / avoids the error. I will also try to close everything on my PC tomorrow and give it a run as is to see if it can handle it with nothing else open.
 
Upvote 0
You may have to rely on someone who is better at Excel vba than me. I'm more of an Access VBA guy.
I look at that and figure you're copying a range to another sheet but using what looks like a 2 dimensional array to do it. I've never seen that approach for that purpose, so I figure I must be wrong about that.

The only other thing I can suggest (and this is only because I can't see the declarations) is that if they're not specifically data-typed (e.g. kk) then you'll end up with a variant variable that will use more memory.
 
Upvote 0
Here are my declarations if it helps.

VBA Code:
    Dim vCols As Variant, vRows As Variant
    Dim ii As Long, kk As Long, nrALL As Long
 
Upvote 0
Is this a realistic example ?
vCols = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17)
They are in order and there are no numbers missing.

Any reason you are not using an output array rather than relying on Index with arrays for the rows and columns ?
Also please post some sample data preferably using XL2BB.
 
Upvote 0
Probably not the best approach, agreed there Alex. I was leveraging older code where the columns would be out of order to its destination. This procedure is pretty uniform, and didn't know a more efficient way so just copied, pasted and modified :rolleyes:

tax lot cons2.xlsx
ABCDEFGHIJKLMNOPQ
1
2
3
4
5
6
7
8D9AC L T QCBCOCCURUCBUYUQCS
9
10DateIndicatorAccountSKU Open Date Lot # QTYLocal CostBase CostOrig CostCurrencyUnit CostBuyerUnique CodeRounded Unit CostFormulaOccurrence
1122-MayAABCG123456781/1/2020110100100100USD10JohnZ10_G12345678102
1222-MayAABCG123456781/1/2021220200200200USD10Tomx10_G12345678202
1322-MayAABCG123456789/1/1999330999999999USD33.3Sallyc33.3_G12345678301
1422-MayAABCG123456781/6/1989440665665665USD16.625Donnav16.63_G12345678401
1522-MayAABCG1234567810/15/2022550140140140USD2.8Timf2.8_G12345678501
1622-MayAABCG123456786/6/1996660356356356USD5.933333333Abigails5.93_G12345678601
1722-MayAABCG123456787/8/1990770985098509850USD140.7142857Mikes140.71_G12345678701
1822-MayAABCG123456784/9/2009880158415841584USD19.8Chirstinew19.8_G12345678801
1922-MayAABCG1234567811/11/2005990458745874587USD50.96666667Sabrinat50.97_G12345678901
2022-MayAABCG1234567810/1/200810100458745874587USD45.87Johnt45.87_G123456781001
Source
Cell Formulas
RangeFormula
O11:O20O11=ROUND(L11,2)
P11:P20P11="_"&D11&G11
 
Upvote 0
See if this works and overcomes your issue:

Rich (BB code):
If Application.WorksheetFunction.CountIf(rng, ">1") > 0 Then
    '----- Changed section -----
    Dim srcRng As Range, srcArr As Variant, destArr As Variant
    Dim j As Long
    
    With WsSec
        Set srcRng = .Range("A11:R" & .Range("H" & Rows.Count).End(xlUp).Row)
    End With
    srcArr = srcRng.Value
    vCols = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17) '<- Columns of interest in specified order
    ReDim destArr(1 To UBound(srcArr), 1 To UBound(vCols) + 1)
    
    For ii = 1 To UBound(srcArr)
        If srcArr(ii, 17) > 1 Then
            kk = kk + 1
            For j = 0 To UBound(vCols)
                destArr(kk, j + 1) = srcArr(ii, vCols(j))
            Next j
        End If
    Next ii
    
    nrAll = WsALL.Range("A" & Rows.Count).End(xlUp).Row + 1
    WsALL.Range("A" & nrAll).Resize(kk, UBound(vCols) + 1).Value = destArr  
    '----- End of Changed section -----
End If
 
Upvote 0
still got an error but this time only the out of memory (runtime 7) so not the warning about 32 or 64 bit. Thought that was interesting....

1717601712839.png


1717601512571.png


but then ran it a second time and it kicked the error here

1717601772723.png
 
Upvote 0
I have logged off for the night.
What is the value of nrAll and of kk when it errors out ?
And was is the last row number in the source data ?
 
Upvote 0

Forum statistics

Threads
1,223,944
Messages
6,175,554
Members
452,652
Latest member
eduedu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top