Results 1 to 8 of 8

Splitting a single column from a file (csv), into several individual files (txt), evenly.

Threaded View

  1. #1
    Registered User
    Join Date
    01-02-2012
    Location
    Melbourne
    MS-Off Ver
    Excel 2003
    Posts
    63

    Splitting a single column from a file (csv), into several individual files (txt), evenly.

    Hi guys,

    I need help for making a code to split my master .csv file into multiple .txt files.

    MY DATA

    - My data is just the one column, from A1 to A1000

    MY REQUIREMENT

    1. I need to split a csv file, containin 1000 names, into 10 separate (equal sized) txt files.

    2. I'd like those files to be named as follows:
    Input_1_100.txt
    Input_101_200.txt
    Input_201_300.txt

    (etc, etc)

    It will be really helpful if someone can help me in this problem, i will be glad to provide sample data or further explanation if necessary.


    Thank you greatly, in advance

    -------------------------------


    update Mon 03/03 6.10pm

    Ive actually managed to convert the column into several rows, each row representing a txt file

    Ive attached the new masterfile (contains macro and is macro enabled), as well as the resulting 10 files (4 of which ive attached)

    The problem is that the names in each file appear in the one row, and not in a neat column (without spaces in between each line)

    So it looks like this:

    James.AJohn.ARobert.AMichael.AWilliam.ADavid.ARichard.AJoseph.ACharles.AThomas.AChristopher.A

    Instead of this:

    James.A
    John.A
    Robert.A
    Michael.A
    William.A
    David.A
    Richard.A
    Joseph.A
    Charles.A
    Thomas.A
    Christopher.A


    Sub WriteTotxt()
    
    Const forReading = 1, forAppending = 3, fsoForWriting = 2
    Dim fs, objTextStream, sText As String
    Dim lLastRow As Long, lRowLoop As Long, lLastCol As Long, lColLoop As Long
    
    lLastRow = Cells(Rows.Count, 1).End(xlUp).Row
    
    For lRowLoop = 1 To lLastRow
    
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set objTextStream = fs.opentextfile("c:\temp\" & Cells(lRowLoop, 1) & ".txt", fsoForWriting, True)
    
        sText = ""
    
        For lColLoop = 1 To 7
            sText = sText & Cells(lRowLoop, lColLoop) & Chr(10) & Chr(10)
        Next lColLoop
    
        objTextStream.writeline (Left(sText, Len(sText) - 1))
    
    
        objTextStream.Close
        Set objTextStream = Nothing
        Set fs = Nothing
    
    Next lRowLoop
    
    End Sub

    I'd appreciate any help on this
    Attached Files Attached Files
    Last edited by Rob8489; 03-03-2014 at 03:19 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Importing Multiple individual txt files into one single spreadsheet using 2003 Excel
    By keige123 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-22-2013, 10:29 PM
  2. Splitting a file into multiple files as per a column
    By DCS2010 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-01-2012, 10:29 AM
  3. Splitting file to several files
    By Hootie in forum Excel General
    Replies: 0
    Last Post: 10-27-2010, 01:31 PM
  4. Replies: 2
    Last Post: 04-03-2006, 05:50 AM
  5. Splitting single column data into two
    By loopkid1 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-31-2006, 01:30 PM

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