+ Reply to Thread
Results 1 to 5 of 5

Export data from Sheet as separate CSV files based on criteria

  1. #1
    Registered User
    Join Date
    02-04-2020
    Location
    Berlin
    MS-Off Ver
    Win10
    Posts
    12

    Export data from Sheet as separate CSV files based on criteria

    Hi all,

    I've been trying to find a solution on this but i have not found any at all : (

    I was wondering if anyone can help me with this issue:

    I have a Excel file (check attached) with 4 columns (A-D), and I am trying to export the data to separate CSV files tab delimited.
    The columns A-D and rows are ALWAYS organized 5 each per name of the file. The name of the file will always be unique.

    ex:
    * for row 2 - 6, i need to export the data from cell B2 - cell D6 as a separate file called "file1.csv"
    * for row 7 - 11, i need to export the data from cell B7 - cell D11 as a separate file called "file2.csv"
    * for row 12 - 16, i need to export the data from cell B12 - cell D16 as a separate file called "file3.csv"

    Note: in each of the CSV files, there are NO info about column A; so basically i don't need column A saved in the new csv files.

    The CSV files are tab delimited so file1.csv contents will be:
    Product 1 page1 detail1
    Product 2 page2 detail2
    Product 3 page3 detail3
    Product 4 page4 detail4
    Product 5 page5 detail5

    file2.csv contents will be:
    Product 6 page6 detail6
    Product 7 page7 detail7
    Product 8 page8 detail8
    Product 9 page9 detail9
    Product 10 page10 detail10

    file3.csv contents will be:
    Product 11 page11 detail11
    Product 12 page12 detail12
    Product 13 page13 detail13
    Product 14 page14 detail14
    Product 15 page15 detail15


    If anyone can help me with this problem, it'd be amazing!

    I attached the excel sheet for reference, of course the columns F-P are just for showing what i mean.
    you can delete these columns.

    Thank you so much!!

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this !


    According to your attachment a VBA beginner starter :

    PHP Code: 
    Sub Demo1()
      Const 
    5
        Dim F
    %, R&, Rw As Range
            F 
    FreeFile
        
    For 2 To [A1].CurrentRegion.Rows.Count Step N
                Open ThisWorkbook
    .Path Application.PathSeparator Cells(R1).Text For Output As #F
            
    For Each Rw In Cells(R2).Resize(N3).Rows
                
    Print #F, Join(Application.Index(Rw.Value2, 0), vbTab)
            
    Next
                Close 
    #F
        
    Next
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  3. #3
    Registered User
    Join Date
    02-04-2020
    Location
    Berlin
    MS-Off Ver
    Win10
    Posts
    12

    Re: Export data from Sheet as separate CSV files based on criteria

    hi Marc L

    thank you so much for the reply!

    the code works just for a few lines from the files

    it created the 3 files but there are some issues with it:
    * file1.csv seems ok
    * file2.csv seems ok even though the spaces seem wider (product 10)
    * file3.csv seems to be the one with issues: there is no space / tab between "Product11" and "page11"

    By the way if my values inside the cells have spaces, i.e. "Product1" is actually "Product 1" (with a spaces after "Product"), will the VBA code still work?

    Thank you!

    PS: i attached screenshots too
    Attached Images Attached Images

  4. #4
    Registered User
    Join Date
    02-04-2020
    Location
    Berlin
    MS-Off Ver
    Win10
    Posts
    12

    Re: Export data from Sheet as separate CSV files based on criteria

    FYI, Just did another test, and seems only file3.csv has that issue, the other ones seem to be ok, even if i add more data in the file, i was able to get correct files further than file3.csv
    (i tested extra data up to file8.csv)

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow

    No such issue on my side and as per Logic if the code fails it fails for all files or none !

    As Notepad is very not the appropriate tool to check such files
    use at least a text editor which can show special characters, like for example Notepad++ …

    Another point : your files are very not csv as csv means the comma as separator (delimiter) !

+ 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. Replies: 19
    Last Post: 02-04-2020, 07:21 PM
  2. [SOLVED] Export data from sheet to sheet based on single criteria
    By WHATSXL in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-27-2017, 01:31 PM
  3. [SOLVED] Automatically export columns to a separate sheet based on initials.
    By Starmusk10 in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 07-11-2016, 08:20 AM
  4. [SOLVED] Split Excel Sheet Data into mutliple files based on two criteria
    By saleembasha in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-22-2016, 12:14 PM
  5. Export Data From One Sheet To Another Based On Criteria
    By chavanalini in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-24-2014, 09:20 AM
  6. [SOLVED] Export Data from one sheet to other based on criteria
    By amy25 in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 07-14-2013, 12:18 PM
  7. Export Data from one sheet to other based on criteria thru programming
    By amy25 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-14-2013, 08:40 AM

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