Macro to import entire text file into single cell

I would need to create an Excel macro to import every single character from a txt file into a single cell in a column. E.g. if text is"test", then "t" would go to A1, "e" to A2, and so on in the spreadsheet. Thank you!

Upvotes: 0

Views: 523

Answers (1)

Gary's Student
Gary's Student

Reputation: 96753

Try to adapt this to your needs:

Sub Macro1()
    Dim s As String, i As Long, j As Long
    Open "C:\TestFolder\Inputs.txt" For Input As #1 Len = 1
    i = 1
    j = 1

    Do Until EOF(1)
        s = Input(1, #1)
        Cells(i, j) = s
        i = i + 1
        If i > Rows.Count Then
            i = 1
            j = j + 1
        End If
    Loop
    Close #1
End Sub

Upvotes: 1

Related Questions