Hi. I'm trying to find a macro that will export or save each row in a spreadsheet to a tab-delimited text file. Any help would be really appreciated. Thanks!
Hi. I'm trying to find a macro that will export or save each row in a spreadsheet to a tab-delimited text file. Any help would be really appreciated. Thanks!
Did you try the code from barryleajo
http://www.excelforum.com/excel-prog...html?p=3311710
and try replacing this
with this?![]()
Print #1, ws.Cells(rownum, colnum) & " ";
or this?![]()
Print #1, ws.Cells(rownum, colnum) & vbTab;
![]()
Print #1, ws.Cells(rownum, colnum) & vbCr;
YES! YES! This worked! Sorry about the two-thread issue. It was not my intent to flood the forum. One more question, if you don't mind. I would like the name of the file to be the row number instead of the data in Column A. How would I incorporate that into the macro? Thanks so very much!
Try changing:
To![]()
filename = .Cells(rownum, 1).Value
Untested.![]()
filename = .Cells(rownum, 1).Row
Thanks,
Solus
Please remember the following:
1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.Highlight the code in your post and press the # button in the toolbar.2. Show appreciation to those who have helped you by clickingbelow their posts.
3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.
"Slow is smooth, smooth is fast."
Yes! Thanks so much for all your help. Saved me hours of work, and maybe more than that in the future.
Last question, I promise. With this code, the worksheet to be split always has to be named "Sheet1" Can it be changed so that it just works with the active sheet instead of the names in the code and worksheet needing to match?
![]()
Sub SplitRowsToTXT() Dim firstrow As Integer, rownum As Integer, colnum As Integer Dim fileName As String Dim Filelocation As String Dim ws As Worksheet Set ws = Worksheets("Sheet1") Filelocation = "C:\Temp\" With ws rownum = 1 While .Cells(rownum, 1) <> "" fileName = .Cells(rownum, 1).Row Open (Filelocation & fileName & ".txt") For Output As #1 colnum = 1 While .Cells(rownum, colnum) <> 0 Print #1, ws.Cells(rownum, colnum) & vbTab; colnum = colnum + 1 Wend Close #1 rownum = rownum + 1 Wend End With End Sub
Have you tried changing this
to this?![]()
Set ws = Worksheets("Sheet1")
![]()
Set ws = ActiveSheet
DerekLee1
For future reference, if your original post is answered, please mark your thread as [solved] and start a new post for new questions.
Hi, XeRo Solus,
as I am curious could you please point the difference between your sample code
and![]()
filename = .Cells(rownum, 1).Row
AFAIR for the Cells rownum has either to be Variant (holding a number), Byte, Integer or Long and will hold the Row.![]()
filename = rownum
Ciao,
Holger
Use Code-Tags for showing your code: [code] Your Code here [/code]
Please mark your question Solved if there has been offered a solution that works fine for you
Holger,
You're absolutely correct. I didn't read into it enough.
Both ways worked for me, but I went with Holger's simpler code. Also for concern of what a blank cell might do to the exports. Thanks all. Got this working perfectly now.![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks