+ Reply to Thread
Results 1 to 14 of 14

import txt or csv delimited parts into different excel sheets

  1. #1
    Registered User
    Join Date
    02-09-2016
    Location
    Bucharest
    MS-Off Ver
    2013
    Posts
    53

    Thumbs up import txt or csv delimited parts into different excel sheets

    Hello friends,

    I'm using excel 2013 and i have a big challenge, i have a big txt file, with more than 400000 lines. Some parts of this file i need to extract and to add them into excel, under different sheets.
    These paragraphs are delimited by % as the beginning and %%% as the end of paragraph.
    I'm doing this manually, copying the selected text, put it in a new excel sheet, rename the sheet with the column title, i'm doing it but it takes me a lot of time. Is there any way to do this automatically?

    Below is a sample of the text file in this subject.
    Thank you in advance.


    Text file:

    %
    Name
    First name|Last name| Age
    John|Smith|55
    Mary|Anne|24
    Nicole|Manda|34
    %%%
    %
    Occupation
    Title|Function|Seniority
    Mr|Director|28
    Mrs|Secretary|3
    Mrs|Accountant|4
    %%%
    %
    Salary
    Crt|Salary|Month
    1|12000|June
    2|2340|June
    3|2800|May
    %%%

    http://www.mrexcel.com/forum/excel-q...el-sheets.html
    http://forum.chandoo.org/threads/imp...-sheets.27751/
    http://www.excelguru.ca/forums/showt...t-excel-sheets
    Last edited by tuspilica; 02-10-2016 at 09:06 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: import txt or csv delimited parts into different excel sheets

    Hi, tuspilica
    The text file has 400.000 lines. Are you gonna extract all to one workbook (with many sheets)?
    How many data parts is it? 1.000? 10.000?
    In your sample each data parts has 5 lines (exclude the % and %%), is that always the case?
    Can you attach some of the data? (unless it’s sensitive data). I need it to see the ‘variations’ & the ‘pattern’ of the data.

  3. #3
    Registered User
    Join Date
    02-09-2016
    Location
    Bucharest
    MS-Off Ver
    2013
    Posts
    53

    Thumbs up Re: import txt or csv delimited parts into different excel sheets

    Hi Akuini,

    i've attached a sample of the txt file.
    The usual size is about 18Mb, i can't upload it here because of it's size, i can share somewhere else.

    The file.txt contains about 50 sections (data parts), but i'm more particulary interested in about 25 of them.
    At least 2 sections contains exactly 5002 rows. These data parts contains different kind of data, as number of rows, columns, ...
    I'm not really interested to extract these sections only into one single workbook, with many sheets. It could be 2 or more with more sheets. But i prefer only one excel file, if possible.

    In between %...%%% sections, it could be any other data rows unframmed by %...%%%, which i'm not interested in.

    What can you say about the sample text attached?

    Many thanks
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: import txt or csv delimited parts into different excel sheets

    Try this macro (backup your data first). Use sample data first. It worked on your sample.
    You have to change the path in code line:
    Please Login or Register  to view this content.
    With 400.000 lines, I don’t know how long it will take, maybe 5 to 10 minutes? Please let me know how long when you’re done.

    Please Login or Register  to view this content.

  5. #5
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,448

    Re: import txt or csv delimited parts into different excel sheets

    Your post does not comply with Rule 8 of our Forum RULES. Do not crosspost your question on multiple forums without including links here to the other threads on other forums.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    http://www.mrexcel.com/forum/excel-q...el-sheets.html
    http://forum.chandoo.org/threads/imp...-sheets.27751/
    http://www.excelguru.ca/forums/showt...t-excel-sheets

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).

  6. #6
    Registered User
    Join Date
    02-09-2016
    Location
    Bucharest
    MS-Off Ver
    2013
    Posts
    53

    Re: import txt or csv delimited parts into different excel sheets

    Thank you for your time and help Akuini!

    Sorry for the inconvinient with crosspost. Itțs completely my fault, i should have read the instructions before posting.

    I run the macro file that you sent to me; the major inconvinient is that it creates me 170 sheets, which is too much.
    I only need just 25 sections from this data file.

    I attached the excel with the 25 sections of interest.

    If it's not too late, i would really apreciate your help.
    Attached Files Attached Files

  7. #7
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: import txt or csv delimited parts into different excel sheets

    Actually there's some inconsistencies regarding what character separate the sections. I thougt it was:
    %%%
    %
    as your sample show in post 1.
    But actually it sometimes just % or just %%%. So my macro won't work.
    I'll modify my macro. I'll get back later.

  8. #8
    Registered User
    Join Date
    02-09-2016
    Location
    Bucharest
    MS-Off Ver
    2013
    Posts
    53

    Re: import txt or csv delimited parts into different excel sheets

    the sections are like this (here are 3 of them):

    File Header
    Line n: % //section 1 starts here
    line n+1: Table_Name (includes String "table")
    line n+2: "|" Delineated Table Headers
    lines n+n: "|" Delineated Columns
    %%%
    unwanted data may occur here
    Line n: % //section 2
    line n+1: Table Name (includes String "table")
    line n+2: "|" Delineated Table Headers
    lines n+n: "|" Delineated Columns
    %%%
    unwanted data may occur here
    Line n: % //section 3 starts here
    line n+1: Table Name (includes String "table")
    line n+2: "|" Delineated Table Headers
    lines n+n: "|" Delineated Columns
    %%%
    unwanted data may occur here


    and the output is like this:

    Row 1 = Table_Name
    Row 2 = TableHeaders
    Rows >=3 = Data
    SheetName = Table_Name (Table...)

    The name of the sheet could be the first word or 15 characters of the Table Name
    Last edited by tuspilica; 02-10-2016 at 10:38 AM.

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: import txt or csv delimited parts into different excel sheets

    Try this one
    Please Login or Register  to view this content.
    Last edited by jindon; 02-10-2016 at 11:07 AM. Reason: Fixed a typo

  10. #10
    Registered User
    Join Date
    02-09-2016
    Location
    Bucharest
    MS-Off Ver
    2013
    Posts
    53

    Re: import txt or csv delimited parts into different excel sheets

    Many thanks Jindon,

    i tried your macro, it works fine, but the major issue is that it extracts all 170 sections into 170 sheets which is really, really hard for me to follow.

    I'm more interested in only 25 sections from the .txt file.
    Do you think it's possible to edit you macro to run just for a few Table sections?
    If necessary i'll modify later the remain sections.
    I attached here above a list with all 25 tables of interest.
    Attached Files Attached Files

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: import txt or csv delimited parts into different excel sheets

    Try this

    You must have all the list in Sheet1 col.A
    All the invalid characters for sheet name will be replaced with "_" underscore.

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    02-09-2016
    Location
    Bucharest
    MS-Off Ver
    2013
    Posts
    53

    Re: import txt or csv delimited parts into different excel sheets

    maybe i'm doing something wrong, after i run the macro, nothing happens.
    i run the macro, it asks me to open the file, i navigate where the txt file is located, i select it, waiting and nothing.
    it's not about macro security, because i deactivate the protection.

    i'm at the office now, but i'll try later from my personal computer. keep you updated

  13. #13
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: import txt or csv delimited parts into different excel sheets

    Changed a bit
    Please Login or Register  to view this content.
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    02-09-2016
    Location
    Bucharest
    MS-Off Ver
    2013
    Posts
    53

    Re: import txt or csv delimited parts into different excel sheets

    Thank you my friend. It works really fine!
    I owe you big time.

    I'll play a little bit with it to add some buttons and if possible to remove the % to do some "beautification"

+ 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. Import a ~ Delimited Text File into Excel
    By vrooom247 in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 12-02-2014, 07:58 AM
  2. import data from tab delimited txt file into on excel sheet
    By flojos in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-05-2013, 08:34 PM
  3. Import space delimited text file into excel
    By vijay2482 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-05-2009, 12:29 PM
  4. Import delimited list into excel template
    By ari_b in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-24-2009, 11:09 AM
  5. How do I import/convert tab delimited text files into Excel?
    By jim in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 05-03-2005, 06:06 PM
  6. Replies: 1
    Last Post: 04-21-2005, 07:06 PM
  7. [SOLVED] I have a Comma delimited text file how do I import in to excel an.
    By trevord in forum Excel General
    Replies: 1
    Last Post: 02-03-2005, 08:06 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