• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Import Text file then split or parse into 2 dimensional array

polarisking

Member
Here's what I want to do
1. Import a large (220MB) pipe-delimited txt file very quickly (this works). Let's say the file has 280,000 rows. At this point I'll have a 1 dimensional array (strData) with 280,000 rows.
2. Now, I want to split each row using the "|" character into another array splitArr that's defined as splitArr(ubound(strData,188)
How Do I Do This?

Thank you in advance
Code:
Sub Sample()

    Dim MyData      As String
    Dim strData()   As String
    Dim splitArr    As Variant
    Dim ctr         As Long
    Dim arrRows     As Long
    Dim arrCols     As Long
    
    Open "FileLocation" For Binary As #1
    MyData = Space$(LOF(1))
    Get #1, , MyData
    Close #1
    
    strData() = Split(MyData, vbLf)
    
    ReDim ArrName(UBound(strData), 188)
    
'Everything's good up to here

'Can I use the SPLIT command to parse out each single line containing 188, separated by "|", values?
    
    Stop
    
End Sub
 
Use Split VBA function to parse the array or better if the data are directly imported within a worksheet use TextToColumns feature …​
 
Use a loop to parse each array element like the post #4 of this thread :​
 
Back
Top