+ Reply to Thread
Results 1 to 9 of 9

Export Each Column on Worksheet as Text File

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-18-2012
    Location
    Telford, England
    MS-Off Ver
    Excel 2010 (2003)
    Posts
    294

    Re: Export Each Column on Worksheet as Text File

    Sub a()
        For C = 1 To ActiveSheet.UsedRange.Columns.Count    
            Columns(C).Select
            sFile = Cells(1, C)
            Selection.Copy                              ' get the data
            Sheets.Add
            ActiveSheet.Paste
            ActiveSheet.Move                            ' spawn neww file
        ' plant the comment in all rows
            ActiveSheet.Range("B1:B" & ActiveSheet.UsedRange.Rows.Count) = sFile
            ActiveSheet.Rows(1).Delete                  ' drop header line
        ' save and close spawned file
            ActiveWorkbook.SaveAs sFile, xlCSV           ' save new file
            ActiveWorkbook.Close False                  ' & close to return to control
        Next
    End Sub

  2. #2
    Registered User
    Join Date
    08-14-2012
    Location
    Dayton, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Export Each Column on Worksheet as Text File

    Hi BrynBaker,

    Thanks for the suggestion. I will do some testing with it to see how it works.

    What line adds the "PC1" to the IP address for each line in the text file? I should have been more specific to add that it won't be the column header. I was shooting to hard code the description part of the text line into the macro. For example, the column might be PC1, but the description on the text line would be "PC Device".

    192.0.0.1, PC Device
    192.0.0.2, PC Device
    192.0.0.3, PC Device
    192.0.0.4, PC Device
    192.0.0.5, PC Device

    The file would still need to be named the same as the column header.

    Also, I assume the location of the file would be the same as the location of the macro enabled Excel file from which this macro is ran, correct?

    I'll test a little later today and let you know how it goes.

    Thanks,
    Ruezo

+ 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