Export each Row to unique Txt file

lmart121

New Member
Joined
Sep 7, 2007
Messages
2
I have a 25000 rows of data in three columns. I need to export each row of data to a unique text file. The text file would look like this:

datafromA1
datafromB1
datafromC1

The file name would need to be datafromA1. I would like to automate the process, and I do not know where to begin. I have always read good advice here but was unable to find something like this task. Thank you in advance.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Requires that each entry in column A is unique because you said the file name should be the value in column A of each respective row. The odds of a duplicate value are pretty good with 25000 records, unless you've already made sure there are no duplicates. Easy to amend the macro if there are dupes so post back if that's an issue.

Based on what you said you want to do and how your data is laid out, this will do what you want:

Code:
Sub TextExport()
Dim strPath$, x&, i%, txt$
strPath = ThisWorkbook.Path & "\"
For x = 1 To Cells(Rows.Count, 1).End(xlUp).Row
Open strPath & Cells(x, 1).Value & ".txt" For Output As #1
txt = ""
For i = 1 To 3
txt = txt & Cells(x, i).Value & vbTab
Next i
Print #1, Left(txt, Len(txt) - 1)
Close #1
Next x
MsgBox "The text files can be found in " & strPath & ".", 64, "Complete"
End Sub
 
Upvote 0
Thank You for the macro. I thankfully do not have any duplicates. I do have a question the output is:

DataA1 DataB1 DataC1

is it possible to have the txt file formatted as:
DataA1
DataB1
DataC1

Thanks again !
 
Upvote 0
Halfway down the macro I posted is this line:
txt = txt & Cells(x, i).Value & vbTab

Substitute vbTab with vbNewLine


So now the line will look like this

txt = txt & Cells(x, i).Value & vbNewLine



Everything else about the macro will remain the same, just make that one small change.
 
Upvote 0

Forum statistics

Threads
1,216,075
Messages
6,128,662
Members
449,462
Latest member
Chislobog

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top