+ Reply to Thread
Results 1 to 13 of 13

Help with approach to create output text files

  1. #1
    Registered User
    Join Date
    02-03-2024
    Location
    London, England
    MS-Off Ver
    Microsoft 365
    Posts
    6

    Help with approach to create output text files

    Thank you in advance for the advice. Keeping it simple to begin with.

    I have a spreadsheet with two columns, column 1 is going to be the name of the text file and column 2 is some information. I have anything from 1 line per file to nearly 200 per file, but to keep it simple here is a set.

    File Title
    100 Mrs
    100 Mrs
    101 Dr
    101 Mr
    102 Miss
    102 Ms
    103 Lord
    104 Sir

    Up to now I have not had these multiple lines and have used

    Please Login or Register  to view this content.
    All attempts I have made with loops, don't step through the lines, but seem to just take the last one.

    What I am looking for is file 100 to have
    <tag>Mrs</tag>
    <tag>Mrs</tag>

    and file 101 to have
    <tag>Dr</tag>
    <tag>Mr</tag>

    Some advice on this would be welcome as I can't find an example to base this on.
    Last edited by wendy.goodier; 02-05-2024 at 06:19 PM.

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

    Re: Help with approach to create output text files

    try
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-03-2024
    Location
    London, England
    MS-Off Ver
    Microsoft 365
    Posts
    6

    Re: Help with approach to create output text files

    Thank you, using the data I showed it falls over at this line which is of course the core of your solution, so I wonder what I have missed

    Please Login or Register  to view this content.
    Last edited by wendy.goodier; 02-03-2024 at 07:38 AM.

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2406 (Windows 11 23H2 64-bit)
    Posts
    82,624

    Re: Help with approach to create output text files

    Administrative Note:

    Welcome to the forum.

    Did you notice that I added code tags to your opening post? Please would you wrap your code in code tags in your latest post?

    Posting code between [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Thanks.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

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

    Re: Help with approach to create output text files

    Your profile shows 365, so it should work.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    02-03-2024
    Location
    London, England
    MS-Off Ver
    Microsoft 365
    Posts
    6

    Re: Help with approach to create output text files

    Thank you so much, now I need to work out which part does which, can you share any insight into why it works, its lots of new functions for me,

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

    Re: Help with approach to create output text files

    1) Get list of unique file names from col.A
    Please Login or Register  to view this content.
    2) Loop through 1) and populate string to output.
    You can insert formula in e.g. D1 to see what the code does.

    ="<tag>"&TEXTJOIN("</tag>"&CHAR(10)&"<tag>",,FILTER(B2:B9,A2:A9=100))&"</tag>"

    D1 need to be wraptext to see line break.

    Please Login or Register  to view this content.
    3) Output for each unique txt file
    Please Login or Register  to view this content.
    HTH

  8. #8
    Registered User
    Join Date
    02-03-2024
    Location
    London, England
    MS-Off Ver
    Microsoft 365
    Posts
    6

    Re: Help with approach to create output text files

    Thank you it does help, as you can imagine I started with it being simple, but actually I have more than one column, maybe I should have explained.

    File Title Surname Address
    1 Mr Apple London
    1 Mrs Orange Oxford
    2 Ms Banana Cambridge

    wanting in file 1

    Please Login or Register  to view this content.
    and standard header and footer tags around each one to eventually create a piece if valid xml.

    I think relying on a Ctl to wrap text means I can't do this.

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

    Re: Help with approach to create output text files

    Now better upload a workbook and text file showing how you want.

  10. #10
    Registered User
    Join Date
    02-03-2024
    Location
    London, England
    MS-Off Ver
    Microsoft 365
    Posts
    6

    Re: Help with approach to create output text files

    Thank you, here are the files.
    The txt shows the xml format with an example of one record per xml (#2) and an example with more than one record per xml (#1).
    The excel contains the records.
    Example excel.xlsx
    filename1.txt
    filename2.txt
    Last edited by AliGW; 02-04-2024 at 05:54 AM. Reason: Redacted for clarity.

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

    Re: Help with approach to create output text files

    try
    Please Login or Register  to view this content.

  12. #12
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,155

    Re: Help with approach to create output text files

    Another alternative is;

    Please Login or Register  to view this content.
    Sample Excel file and a screenshot of the first XML file attached below.
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by Haluk; 02-04-2024 at 12:21 PM.

  13. #13
    Registered User
    Join Date
    02-03-2024
    Location
    London, England
    MS-Off Ver
    Microsoft 365
    Posts
    6

    Re: Help with approach to create output text files

    Thank you to everyone that helped, appreciate the useful solutions.

+ 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. [SOLVED] Output excel data to text (or Word) files with column headers included
    By Tez42 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-30-2020, 12:10 AM
  2. Macro to output rows of data as separate text files ?
    By Dale Saukerson in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-30-2020, 05:22 PM
  3. [SOLVED] Create and output to a text file (test.txt)
    By sirkusjon in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-30-2020, 04:57 AM
  4. Replies: 0
    Last Post: 11-26-2012, 05:51 PM
  5. Input/Output text files fill in variables
    By cfunky in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-10-2010, 10:20 AM
  6. control-M characters in text files output from Excel
    By embirath in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-28-2006, 01:44 AM
  7. [SOLVED] How do I export Lotus Approach files into an Excel spreadsheet?
    By LEWOLF in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 03-20-2006, 01:25 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