VBA Exporting Filled Rows to Individual Text Files

Important Notice

Please note that on 14th December 2023 users will experience an expected outage whilst we make upgrades to our network. We anticipate this process may take a couple of hours and so we apologise in advance for any inconvenience.

  • 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:

    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
    End Sub

Participate now!

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