Facing "out of memory" issue while importing data from a .csv file to create Pivot Cache

SeriousDeveloper

New Member
Joined
Dec 20, 2013
Messages
2
Hi All,

I need a help on this issue which we are facing.

We are trying to create pivot cache from an external .csv file.

This works fine when the csv file is small (<500 mb).
But it given "out of memory" error for bigger .csv files(>~500 mb).

Attaching sample code for reference -

Code:
Dim cConnection As ADODB.Connection
Dim rsRecordset As ADODB.Recordset
Dim pvtCache As PivotCache
Dim pvtTable As PivotTable
 Dim SQL As String

''Creating ADODB connection object
 Set cConnection = New ADODB.Connection
 cConnection.Open sConnStrP1 & sFilePath & sConnStrP2

'' where
'''Const sConnStrP1 = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq="
'''Const sConnStrP2 = ";Extensions=asc,csv,tab,txt;Persist Security Info=False"
'''Const sFilter = "CSV File, *.csv"


  Set rsRecordset = Nothing
    Set rsRecordset = New ADODB.Recordset
    Set rsRecordset = cConnection.Execute(SQL)
            
''Creating pivot cache from csv file
    Set pvtCache = ThisWorkbook.PivotCaches.Create(SourceType:=xlExternal)
    Set pvtCache.Recordset = rsRecordset

''Using Pivot cache to create pivot table
 arrTmp = Array("NoRow")
 Set pvtTable = createPivotTable(arrTmp, wsTemp.Range("f15"), pvtCache)
 pvtTable.Name = "ptbl_1"
Is there a way we can solve this issue. If not what is the best way to create a pivot table for >4-5 millions records.

It will be great help if someone can put some helpful pointers.
 
Last edited by a moderator:

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
I suspect you probably need 64bit Excel, or perhaps Powerpivot.
 
Upvote 0
I suspect you probably need 64bit Excel, or perhaps Powerpivot.

Thanks for the prompt response RoryA.

Unfortunately 64 bit excel does not supports ADODB connection object. Powerpivot will require us to force our users to download it on their machines.
There has to be some other way for this??
 
Upvote 0
excel worksheet has a limit of 1048576 rows

you would have to split your data

also, your code does not show the SQL string, have you checked if it is correct
 
Upvote 0
excel worksheet has a limit of 1048576 rows

you would have to split your data

also, your code does not show the SQL string, have you checked if it is correct

The worksheet has a limit of 1,048,576 rows, but this limit does not apply to a PivotCache. I've had PivotCaches with upwards of 14,000,000 records for some apps. If one points a PivotTable to an external data source, such as a MySQL or SQLServer query, the returned PivotCache becomes part of the workbook, even though it cannot be displayed in its entirety within any single worksheet.

I am having a problem converting one app from using MS SQLServer to MySQL as a data source. The 13 MM record dataset comes back from MS SQL without a problem. The same table sourced from MySQL causes and Excel out of memory error at 10.6 MM records.
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,916
Members
449,093
Latest member
dbomb1414

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