Reading data from text file and delimiting

后端 未结 1 1436
萌比男神i
萌比男神i 2020-12-19 13:25

I have an Excel 2010 spreadsheet, and I am reading in information from a .txt file (and another .xls file in future).

This text file has 3 elements per row; firtname

1条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-19 13:52

    Sub FetchDataFromTextFile()
        Dim i As Long
        Dim LineText As String
        Open "C:\mytxtfile.txt" For Input As #24
        i = 2
        While Not EOF(24)
            Line Input #24, LineText
                Dim arr
                arr = Split(CStr(LineText), ", ")
                For j = 1 To 
                    ActiveSheet.Cells(i, j).Value = arr(j - 1)
                Next j
                i = i + 1
        Wend
        Close #24
    End Sub
    

    For different delimiters, make use of the answers in here

    0 讨论(0)
提交回复
热议问题