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
    1. Sub Create_Text_Files()
    2. Dim row As Long, lastRow As Long
    3. lastRow = Cells(Rows.Count, "A").End(xlUp).row
    4. For row = 2 To lastRow
    5. Open "C:\folder\folder2\" & Cells(row, "A").Value & ".txt" For Output As #1
    6. Print #1, Cells(row, "B").Value
    7. Close #1
    8. Next
    9. End Sub