+ Reply to Thread
Results 1 to 10 of 10

Exporting each row as tab-delimited text

Hybrid View

DerekLee1 Exporting each row as... 07-06-2013, 04:54 PM
jolivanes Re: Exporting each row as... 07-06-2013, 05:14 PM
DerekLee1 Re: Exporting each row as... 07-06-2013, 06:43 PM
Solus Rankin Re: Exporting each row as... 07-06-2013, 07:09 PM
DerekLee1 Re: Exporting each row as... 07-06-2013, 07:43 PM
jolivanes Re: Exporting each row as... 07-07-2013, 03:11 AM
Solus Rankin Re: Exporting each row as... 07-07-2013, 04:47 AM
HaHoBe Re: Exporting each row as... 07-07-2013, 04:53 AM
Solus Rankin Re: Exporting each row as... 07-07-2013, 01:33 PM
DerekLee1 Re: Exporting each row as... 07-07-2013, 05:28 PM
  1. #1
    Registered User
    Join Date
    07-06-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    5

    Exporting each row as tab-delimited text

    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!

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,700

    Re: Exporting each row as tab-delimited text

    Did you try the code from barryleajo

    http://www.excelforum.com/excel-prog...html?p=3311710

    and try replacing this

    Print #1, ws.Cells(rownum, colnum) & " ";
    with this?

    Print #1, ws.Cells(rownum, colnum) & vbTab;
    or this?

    Print #1, ws.Cells(rownum, colnum) & vbCr;

  3. #3
    Registered User
    Join Date
    07-06-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Exporting each row as tab-delimited text

    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!

  4. #4
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Exporting each row as tab-delimited text

    Try changing:

    filename = .Cells(rownum, 1).Value
    To

    filename = .Cells(rownum, 1).Row
    Untested.
    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 clicking below 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."

  5. #5
    Registered User
    Join Date
    07-06-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Exporting each row as tab-delimited text

    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

  6. #6
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,700

    Re: Exporting each row as tab-delimited text

    Have you tried changing this

    Set ws = Worksheets("Sheet1")
    to this?

    Set ws = ActiveSheet

  7. #7
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Exporting each row as tab-delimited text

    DerekLee1

    For future reference, if your original post is answered, please mark your thread as [solved] and start a new post for new questions.

  8. #8
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Exporting each row as tab-delimited text

    Hi, XeRo Solus,

    as I am curious could you please point the difference between your sample code
    filename = .Cells(rownum, 1).Row
    and
    filename = rownum
    AFAIR for the Cells rownum has either to be Variant (holding a number), Byte, Integer or Long and will hold the Row.

    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

  9. #9
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Exporting each row as tab-delimited text

    Holger,

    You're absolutely correct. I didn't read into it enough.

  10. #10
    Registered User
    Join Date
    07-06-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Exporting each row as tab-delimited text

    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.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1