Howdy,

Firstly, I am a total beginner when it comes to VBA programming but I am keen to learn and dont want to be dissuaded in doing so by a few bumps in the road.

I have 10 .csv files each containing 800,000+ rows (all in the same folder entitled 1.csv, 2.csv, 3.csv etc). I am looking to bring them into 1 excel workbook (each in a different worksheet) and from there pivot table each worksheet to produce an overall 'average' pivot table.

The first issue I encountered was being able to copy and paste such large .csv files into Excel (Excel 2010). The only way I have managed to do so manually was by importing the data through Data>Get Extrenal Data> From Text.

By way of viewing macros and similar codes online I have come up with the following:

--------------------------------------------------------

Sub TEST()
'
' TEST Macro
'

'
For i = 1 To 10
Sheets.Add
ActiveSheet.Name = i & ".csv"
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;D:\Erskine Bridge 2012\## Calibration ##\## Models ##\Base Model - Erskine Bridge 2012\Log\Path Journey Time Runs\" & i & ".csv" _
, Destination:=Range("$A$1"))
.Name = "1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 _
, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
ActiveWorkbook.Connections("1").Delete
Next i
End Sub

----------------------------------------------------

At the moment Im just trying to investigate how to bring in the .csv automat

When I run the code it works for 1.csv, creates the sheet for 2.csv and gives me the error 'Run Time Error 7 - out of memory'. This is pretty much my first go at any VBA programming so Im trying not to give up on this so any help would be greatly appreciated.

1.csv, 2.csv, 3.csv files are each 150Mb

Thanks in advance

Richard