VBA Exporting Filled Rows to Individual Text Files

  • Here's my problem:


    I have a Text ID Column and a Text Column. I need to save each row of the Text Column into its own individual text file on my C: Drive. The name of the file should be the the Text ID from the first column. I need this to work with different sample data, so the number of rows will vary. I also need this to be able to work with excel files that contain thousands of rows.

  • Re: VBA Exporting Filled Rows to Individual Text Files


    Assuming the data is in columns A and B (you didn't say, but change the obvious in the code if not) and create files in C:\folder\folder2\, try this:

    Code
    Sub Create_Text_Files()
        Dim row As Long, lastRow As Long
        lastRow = Cells(Rows.Count, "A").End(xlUp).row
        For row = 2 To lastRow
            Open "C:\folder\folder2\" & Cells(row, "A").Value & ".txt" For Output As #1
            Print #1, Cells(row, "B").Value
            Close #1
        Next
    End Sub

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!