Results 1 to 8 of 8

Export Each Excel Row as Separate Files with Header Row

Threaded View

  1. #1
    Registered User
    Join Date
    07-21-2016
    Location
    Discovery Bay, CA
    MS-Off Ver
    Office 2010
    Posts
    17

    Export Each Excel Row as Separate Files with Header Row

    Ladies and Gentlemen, I'm stumped and would appreciate your expertise. I have researched this here and elsewhere, but the answer eludes me.
    Summary: I just want to export each row of an Excel file to a new file, but I must have the same header row for each file. Also, some cells are blank, but they still must be included.
    Details:
    Excel Worksheet with 13 Columns (A-M) and 11 Rows (1-11)
    Row 1 is the header row which must be included in each file
    Contents of each row must be exported to a new file
    Column A for each row is used for the name of the new file
    If any Cells are blank, EXCEPT Column 1, they still must be included in the new file.
    Script should continue until a blank value in Column A
    I need to be able to code the directory for the output.
    I will attach what I have so far - not elegant, it works, but does not give me what I need.
    It only takes the individual row with no header and exports to the directory where the workbook is open.

    Sub ExportRows()
        Dim r As Range, r2 As Range
        Dim ff As Integer
        Dim s As String
        
        For Each r In Range("a1", Range("a" & Rows.Count).End(xlUp))
            s = ""
            For Each r2 In Range(r, Cells(r.Row, Columns.Count).End(xlToLeft))
              If VarType(r2) = vbString Then
                s = s & "," & """" & r2.Value & """"
                Else
                s = s & "," & r2.Value
              End If
            Next r2
            s = Right(s, Len(s) - 1)
            ff = FreeFile
            Open ThisWorkbook.Path & "\" & Format(r.Row, "000000") & ".au" For Output As #ff
            Print #ff, s
            Close #ff
        Next r
    End Sub


    Worksheet.jpg
    Attached Files Attached Files
    Last edited by JBeaucaire; 07-21-2016 at 10:46 PM. Reason: Added missing CODE tags. Please read and follow the Forum Rules, link above in the menu bar. Thanks.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] writing excel file to separate tab separated text files with header in each
    By gsindby in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-15-2014, 10:19 AM
  2. Export Columns to separate Text files
    By murtly in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-31-2014, 08:25 AM
  3. Simple Macro to Export Each Cell as Separate Files
    By Moop in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-16-2013, 12:55 PM
  4. Export each row to separate TXT (header row always included)
    By tvancoillie in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-14-2012, 04:28 AM
  5. Replies: 0
    Last Post: 11-09-2009, 09:57 AM
  6. split it into groups of 100 and export it to separate .csvs or text files
    By Shaunclippo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-03-2006, 01:40 PM
  7. [SOLVED] Open Excel files in separate sessions, not just separate windows?
    By Bob at Dexia Design in forum Excel General
    Replies: 1
    Last Post: 10-18-2005, 01:05 PM

Tags for this Thread

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