+ Reply to Thread
Results 1 to 14 of 14

Saving file as txt with original delimiter ?

  1. #1
    Registered User
    Join Date
    07-24-2024
    Location
    Canada
    MS-Off Ver
    365
    Posts
    99

    Saving file as txt with original delimiter ?

    Hello,

    This is my text test file : test file.txt

    It looks like this originally :
    screenshot test file.jpg

    As you can see, the text file contains a delimiter (^). Sometimes this text file contains errors that we must fix manually. The solution to most of our problems with this file is to delete one or multiple lines and adjust the number of lines (D1^1 to 4 in the sample file) accordingly. So if we delete line 2 then 3 becomes 2 and 4 becomes 3. It wouldn't be so bad if the real files did not contain up to 1000 lines. We are currently editing everything manually. However, before editing the file manually, we open it in Excel because that makes it way easier to read, that way it is easier to see where the problem is.

    Adding the txt file opened with excel : delimiter excel.xlsx

    That is very clear. Very easy to read. The problem is that we can't edit the file in excel because it contains a delimiter, and when we save, it doesn't add it back.

    This is the txt file after saving : saved txt.txt

    And it looks like this :
    screenshot saved file.jpg

    This file as it is (when saved with excel) is unusable inside our data management tool. If the problems lies in line D1^50 and we must delete the line, and if there are a total of 800 lines, adjusting them all one by one so that the last line is D1^799 instead of D1^800 takes a very very long time.

    I am wondering, is there anything that we can do in excel so that when we modify the file in excel, we can save it and it will appear like the original file ? It would be so much faster to simply drag down and autofill the numbers.

    Thank you !
    Last edited by MasterBash; 10-10-2024 at 09:27 PM.

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,160

    Re: Saving file as txt with original delimiter ?

    Paste this into a regular module :

    Please Login or Register  to view this content.
    First select all the cells in the sheet that you want to apply this macro to. Then run the macro.
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    07-24-2024
    Location
    Canada
    MS-Off Ver
    365
    Posts
    99

    Re: Saving file as txt with original delimiter ?

    Thank you ! The only problem that I can see is a space next to the ^ ( ^).
    Is that possible to remove so there are no spaces?

    Thanks. 🙂

  4. #4
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,160

    Re: Saving file as txt with original delimiter ?

    The macro when run here, doesn't inject a blank space. I don't know why that is happening on your end.\

    I've made an improvement to the macro as seen below. This new macro does not require you to first select the cells you want the macro to be applied to.
    You can simply click the command button and the macro does the rest.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    07-24-2024
    Location
    Canada
    MS-Off Ver
    365
    Posts
    99

    Re: Saving file as txt with original delimiter ?

    I apologize if I wasn't clear.

    The space appears in the text file only (as if someone pressed tab) when saving from excel in text format or copy pasting.

    The second code adds the ^ to the first column.

    The end result should look exactly like the test file when it comes to spaces and ^.

  6. #6
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,160

    Re: Saving file as txt with original delimiter ?

    Look at the attached TXT file. Is this what you are referring to ? If so, even copy/paste from Excel to a text file ... there is no extra space.
    Attached Files Attached Files

  7. #7
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,160

    Re: Saving file as txt with original delimiter ?

    I've been exploring more options for the macro and have developed the following :

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    07-24-2024
    Location
    Canada
    MS-Off Ver
    365
    Posts
    99

    Re: Saving file as txt with original delimiter ?

    Thank you ! Your code is working well.

    By space, I meant the empty areas :

    Attachment 880850

    There are more, but I circled some of them. Initially, if I were to open the txt file in excel without a delimiter, each rows would be in one single column (A). I wonder if it is possible to go back to a "non-delimited" version (but keeping the delimiter inside the text), after I make my modifications, before saving or copy pasting.

  9. #9
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,160

    Re: Saving file as txt with original delimiter ?

    Attachments dont work. You need to use Go Advanced and upload the file.

  10. #10
    Registered User
    Join Date
    07-24-2024
    Location
    Canada
    MS-Off Ver
    365
    Posts
    99

    Re: Saving file as txt with original delimiter ?

    What the original file is supposed to look like : screenshot test file.jpg

    What the spaces look like : emptyspace.jpg

    When I look with notepad or anything else, it seems like that empty space counts as one character.

    EDIT :

    I found this code below and I modified it :

    Please Login or Register  to view this content.
    So in a cell, I am using :

    Please Login or Register  to view this content.
    Substitute because there are too many ^ on the first line and last line, and that I dragged the formula for the first 1000 lines.

    Before marking this thread as solved, I will make sure to text it out then I will mark it as solved if there are no issues. I would still like to say thank you for your help ! If the function works however, the button may not be necessary.
    Last edited by MasterBash; 10-11-2024 at 09:15 PM.

  11. #11
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,160

    Re: Saving file as txt with original delimiter ?

    The image you posted after the words ... "What the spaces look like :" .... is that a representation of the data in the cells after processing with the macro I provided ?

    If so ... those 'spaces' are not really spaces. That is just the manner that Excel visually presents the data in each cell. You can prove there are no spaces by clicking on
    VIEW in the menu bar, the click on 'Formula Bar' to activate it. Now click on any cell and the data in that cell will appear in the Formula Bar. Now click in the Formula Bar
    anywhere after the data/term shown in the Formula Bar. The cursor should show up immediately after the last letter of the term displayed. That proves there are no
    extra spaces being injected.

  12. #12
    Registered User
    Join Date
    07-24-2024
    Location
    Canada
    MS-Off Ver
    365
    Posts
    99

    Re: Saving file as txt with original delimiter ?

    Yes, I understand that. However, in the text file, it does add a wide space (similar someone pressing tab). I was able to select it/highlight it and it definitely counts as a character.

    Updated workbook : ace test.xlsb

    I did some adjustment to the file, so it does not do that and there are less modifications to be made.

    However, this also causes another problem if someone can help me out with this :

    The code that is used to save the sheet is save multiple empty lines under the last cell containing value. This is because I dragged down the formula for the first 1000 lines. I wonder if it is possible to change the code a bit to simply save the cells that contain a value and not the empty cells just because they have a formula in it.

    The last row is always the one that starts with S1.

    The code is inside the ACE module.

    Please Login or Register  to view this content.
    Thank you.
    Last edited by MasterBash; 10-12-2024 at 12:53 AM.

  13. #13
    Registered User
    Join Date
    07-24-2024
    Location
    Canada
    MS-Off Ver
    365
    Posts
    99

    Re: Saving file as txt with original delimiter ?

    Posting back as I found a solution, in case anyone is interested in finding the last row containing specific text.

    Please Login or Register  to view this content.
    This line specifically :
    Please Login or Register  to view this content.
    I will mark this thread as solved. I will post back if there are any problems, but after testing it out with multiple files, they look exactly like the original.

    Thank you for your kind help, Logit.

  14. #14
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,160

    Re: Saving file as txt with original delimiter ?

    You are welcome.

+ 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] Keep original file open after saving modified copy
    By shepardrf in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-20-2024, 10:32 AM
  2. Saving a file without unloading the original
    By Phixer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-06-2015, 12:45 PM
  3. creating a copy of a file but not saving original
    By Mattneedshelp in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-07-2013, 05:29 AM
  4. Replies: 3
    Last Post: 11-28-2011, 03:08 PM
  5. Replies: 1
    Last Post: 12-02-2007, 05:52 AM
  6. Replies: 1
    Last Post: 08-15-2005, 06:05 PM
  7. [SOLVED] Lost my original spreadsheet by saving over it with the same name
    By dough office manager in forum Excel General
    Replies: 1
    Last Post: 01-07-2005, 08:06 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