I would like to read data from 831 MB text file. Unfortunately I got Run-time error 14. Out of string space. How can I change the code? I think is should be possible to read the whole data into an array on my notebook (W10 64 bit, 24 GB RAM, CPU 7500U, Excel 2016).
You can get data from The Global Drifter Program (buoydata_15001_jun16.dat). I need to process data from first 7 columns separated by spaces not by semicolon only.
Sub DelimitedTextFileToArray()
'PURPOSE: Load an Array variable with data from a delimited text file
'SOURCE: www.TheSpreadsheetGuru.com
Dim Delimiter As String
Dim TextFile As Integer
Dim FilePath As String
Dim FileContent As String
Dim LineArray() As String
Dim DataArray() As String
Dim TempArray() As String
Dim rw As Long, col As Long
'Inputs
Delimiter = ";"
FilePath = "C:\buoydata_15001_jun16.txt"
rw = 0
'Open the text file in a Read State
TextFile = FreeFile
Open FilePath For Input As TextFile
'Store file content inside a variable
FileContent = Input(LOF(TextFile), TextFile)
'Close Text File
Close TextFile
'Separate Out lines of data
LineArray() = Split(FileContent, vbCrLf)
'Read Data into an Array Variable
For x = LBound(LineArray) To UBound(LineArray)
If Len(Trim(LineArray(x))) <> 0 Then
'Split up line of text by delimiter
TempArray = Split(LineArray(x), Delimiter)
'Determine how many columns are needed
col = UBound(TempArray)
'Re-Adjust Array boundaries
ReDim Preserve DataArray(col, rw)
'Load line of data into Array variable
For y = LBound(TempArray) To UBound(TempArray)
DataArray(y, rw) = TempArray(y)
Next y
End If
'Next line
rw = rw + 1
Next x
End Sub