+ Reply to Thread
Results 1 to 3 of 3

Split Excel file into multiple Excel files based on specific column value

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-22-2014
    Location
    Indonesia
    MS-Off Ver
    2010
    Posts
    177

    Split Excel file into multiple Excel files based on specific column value

    Hello,

    it's been a while not visiting this forum. Hope everyone is good

    Anyway, i have i macro to split csv file into multiple csv files based on spesific column value.

    here's the code:

    Sub Splitsinglecsvintomultiplecsv()
         
        Dim FF As Integer
        Dim wLine As String
        Dim saveLocation As String
        Dim cID As String
        Dim lRow As Long
         
        saveLocation = "D:\" '//Change as required, make sure you have a trailing "\"
        
        Cells(2, 5).Activate
         
        Do
            FF = FreeFile
            cID = ActiveCell.Value
            Open saveLocation & cID & ".txt" For Output As #FF
            Print #FF, "No,data1,data2,data3,data4,data5"
    
            While ActiveCell.Value = cID
                lRow = ActiveCell.Row
                Print #FF, Cells(lRow, 1) & "," & Cells(lRow, 2) & "," & Cells(lRow, 3) & "," & Cells(lRow, 4) & "," & Cells(lRow, 5) & "," & Cells(lRow, 6)
                ActiveCell.Offset(1, 0).Activate
            Wend
            Close #FF
            Name saveLocation & cID & ".txt" As saveLocation & cID & ".csv"
        Loop Until ActiveCell.Value = ""
         
    End Sub
    it work to split file based on specific column value that i have set. How ever there is error on result each file.
    the cell contain several commas split into multiple column causing not match with the header.

    appreciate if anyone can check the code.

    also i want to save the result as .xlsx as current result is in .csv format.


    Thank you.

  2. #2
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,301

    Re: Split Excel file into multiple Excel files based on specific column value

    Quote Originally Posted by qiyusi View Post
    ... i have i macro to split csv file into multiple csv files based on spesific column value ...
    ... also i want to save the result as .xlsx as current result is in .csv format ...
    This macro does not split the "csv" file into many other "csv" files.
    This macro creates many "csv" files from the excel sheet content based on the data from the "E" column cells.

    What is the "input material" for the division and what should be the "output material" of the division ?
    a) one excel sheet to many csv files ?
    b) one csv file (txt file) to many csv files (txt files) ?
    c) one excel sheet to many csv files and many xls files ?

    Give us maybe an example of files - input/output file - the data does not have to be true.

  3. #3
    Forum Contributor
    Join Date
    10-22-2014
    Location
    Indonesia
    MS-Off Ver
    2010
    Posts
    177

    Re: Split Excel file into multiple Excel files based on specific column value

    Hello,

    Really sorry for very late respond.

    Attached is the Example file with the explanation.


    Thank you.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Split one Excel file into multiple files based on values in column A?
    By MetroBOS in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-06-2015, 10:59 AM
  2. Split excel file having multipl sheets into multiple excel file based on column
    By Shaharyarwatto in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-22-2014, 05:02 AM
  3. Split Excel into Multiple csv files based upon the sum of column count.
    By sukanya123 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-02-2013, 07:28 PM
  4. Split Excel file into multiple files based on number of rows
    By kingtut86 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-24-2013, 03:38 PM
  5. [SOLVED] How To Split Excel File Into Separate Workbooks Based on Values In a Specific Column
    By UzieJacuzzi in forum Excel Programming / VBA / Macros
    Replies: 30
    Last Post: 07-31-2012, 07:26 AM
  6. [SOLVED] Split Large Excel file to multiple excel files and possible save the files
    By EnzioL in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-20-2012, 03:28 AM
  7. Replies: 3
    Last Post: 08-02-2006, 12:35 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