Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is CSV file too big for Excel?

Status
Not open for further replies.

ktwclark

Programmer
Jan 30, 2002
54
GB
I have a CSV file that is produced from one of our corporate systems every month and is processed using a macro I have written. The problem I have is that if the CSV file has more than 65535 rows then it is too big to be imported in to Excel. However, Excel will import 65535 rows of data from the CSV file and discard the rest.

I'm looking for a way to determine if there are more than 65535 rows of data in the CSV file. I know I could open the file then move to its end and check the row nunber, but I was looking for something a bit more advanced, such as an error code when the CSV is too big. I've been unsuccessful so far to trap this error.

There is no conformity to cell contents either, so file size is out.

Any help would be appreciated.

Thanks
 
Well,

Easiest solution is to stop using excel and start using access i quess... "In three words I can sum up everything I've learned about life: it goes on."
- Robert Frost 1874-1963
 
There are ways to get around the limitation. If you have less than 98,303 rows then you can use the import wizard to import the csv file. The first 65,536 rows of the text file will be imported into a worksheet, and then you will get an error “File Not Loaded Completely”
Click OK. Save this workbook.

Repeat importing the file. In the Text Import Wizard step 1 of 3, select 32767 for "Start Import at Row," and click Finish. Next 65,536 rows will now be imported. You will need to delete the first 32,766 rows in this workbook because these rows were also imported into the first workbook. Save this workbook.

Now you can bring the two spread sheets together.

If you have more than 98,303 rows, here is an import macro from Microsoft

'All lines that begin with an apostrophe (') are remarks and are not
'required for the macro to run.
Sub LargeFileImport()

'Dimension Variables
Dim ResultStr As String
Dim FileName As String
Dim FileNum As Integer
Dim Counter As Double
'Ask User for File's Name
FileName = InputBox("Please enter the Text File's name, e.g. test.txt")
'Check for no entry
If FileName = "" Then End
'Get Next Available File Handle Number
FileNum = FreeFile()
'Open Text File For Input
Open FileName For Input As #FileNum
'Turn Screen Updating Off
Application.ScreenUpdating = False
'Create A New WorkBook With One Worksheet In It
Workbooks.Add template:=xlWorksheet
'Set The Counter to 1
Counter = 1
'Loop Until the End Of File Is Reached
Do While Seek(FileNum) <= LOF(FileNum)
'Display Importing Row Number On Status Bar
Application.StatusBar = &quot;Importing Row &quot; & _
Counter & &quot; of text file &quot; & FileName
'Store One Line Of Text From File To Variable
Line Input #FileNum, ResultStr
'Store Variable Data Into Active Cell
If Left(ResultStr, 1) = &quot;=&quot; Then
ActiveCell.Value = &quot;'&quot; & ResultStr
Else
ActiveCell.Value = ResultStr
End If

'For xl97 and later change 16384 to 65536
If ActiveCell.Row = 16384 Then
'If On The Last Row Then Add A New Sheet
ActiveWorkbook.Sheets.Add
Else
'If Not The Last Row Then Go One Cell Down
ActiveCell.Offset(1, 0).Select
End If
'Increment the Counter By 1
Counter = Counter + 1
'Start Again At Top Of 'Do While' Statement
Loop
'Close The Open Text File
Close
'Remove Message From Status Bar
Application.StatusBar = False

End Sub


NOTE: The macro does not parse the data into columns. After using the macro, you may also need to use the Text To Columns command on the Data menu to parse the data as needed.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top