+ Reply to Thread
Results 1 to 10 of 10

Remove last three lines of text files

  1. #1
    Forum Contributor
    Join Date
    07-19-2012
    Location
    Redmond, WA
    MS-Off Ver
    O365
    Posts
    133

    Remove last three lines of text files

    Hi. I am working on importing text files which works for the most part. Per the code below, I create anywhere from 8 to 30 text files (depending on several factors) that can vary in size between 2000 lines and 20000 lines.
    The last three lines of each of these text files is always the same. I need to remove these last three lines from the text files prior to importing them into the spreadsheet.

    Any help here is greatly appreciated.

    Please Login or Register  to view this content.
    Rep is appreciated. Click my * if I helped.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Remove last three lines of text files

    Hello ussentterprise,

    Are you downloading the text file or viewing it in the PuTTY window?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    07-19-2012
    Location
    Redmond, WA
    MS-Off Ver
    O365
    Posts
    133

    Re: Remove last three lines of text files

    Hello Leith,

    The macro opens a PuTTY window with logging to create a text file based on the VV variable.

    Edit: The text file is them imported into Excel. For formatting purposes, I need to remove the last three lines.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Remove last three lines of text files

    Hello ussentterprise,

    The text file is automatically opened in Excel after the Shell command executes? Is this a new instance of Excel or do you have Excel already open?

  5. #5
    Forum Contributor
    Join Date
    07-19-2012
    Location
    Redmond, WA
    MS-Off Ver
    O365
    Posts
    133

    Re: Remove last three lines of text files

    Hello Leith,

    Excel is open when the macro runs. The text files are set to import when Excel opens. So, no data other than the previous opening of Excel is present. At some point, I may set the import to refresh at certain intervals.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Remove last three lines of text files

    Hello ussenterprise,

    Try this...
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    07-19-2012
    Location
    Redmond, WA
    MS-Off Ver
    O365
    Posts
    133

    Re: Remove last three lines of text files

    This looks like it applies after the text file is imported. Not quite what I am looking for, but I will give it shot and let you know.

    I'll have to set a loop up to work with the "data" sheets.

    Thanks!

  8. #8
    Forum Contributor
    Join Date
    07-19-2012
    Location
    Redmond, WA
    MS-Off Ver
    O365
    Posts
    133

    Re: Remove last three lines of text files

    Good morning Leith,

    Here is what I have come up with:

    Please Login or Register  to view this content.
    The autofit takes care of formatting issues.

    Curiously, the very last line is not removed. However, the primary cause of needing this done is taken care of.

    Next up is to get this to run automatically after the worksheet is opened and all data has been imported.

    Thanks!

    Edit - The line that needed to be removed:
    "---------------------------------------------------------------------------------------------------------------------------"
    This caused column B to be far too wide.
    Last edited by ussenterprise; 09-25-2019 at 10:49 AM.

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Remove last three lines of text files

    Hello ussenterprise,

    Nice work. I have PuTTY but do not use it very often. Obviously, I could learn quite bit from you on how to use it.

    If you can change the refresh rate then it seems there should also be a flag available to signal when it has finished. Since I do not know the method you are using to refresh the data, I can not say for sure, but there should be a flag or event to indicate when it is done. I would use either of these to automatically run the macro.

  10. #10
    Forum Contributor
    Join Date
    07-19-2012
    Location
    Redmond, WA
    MS-Off Ver
    O365
    Posts
    133

    Re: Remove last three lines of text files

    Hello Leith,

    I had to make some minor adjustments. PuTTY was taking too long through the loop, so I switched to plink. This changed the formatting slightly so I had to adjust your code. The formatting change is now to delete the last two lines.

    Please Login or Register  to view this content.

+ 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] Convert text to data and remove specific lines
    By SubwAy in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-13-2017, 07:20 AM
  2. remove line or lines from a text file using vba if checkbox is true
    By cmccabe in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-12-2016, 02:12 PM
  3. [SOLVED] Remove lines based on cell value (remove lines in range, not entire row)
    By Tapyr in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-27-2015, 07:31 AM
  4. [SOLVED] Macro neede to open text files from folder and remove all the lines except specific lines
    By genetist in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 10-07-2014, 02:44 AM
  5. Formulas to remove specific lines of text from a spreadsheet
    By visionwindowfilms in forum Excel General
    Replies: 11
    Last Post: 02-28-2010, 06:04 PM
  6. No blank lines in text files
    By Charlie Gotwald in forum Excel General
    Replies: 3
    Last Post: 09-01-2005, 04:05 PM
  7. No blank lines in text files
    By Charlie Gotwald in forum Excel General
    Replies: 1
    Last Post: 09-01-2005, 04:05 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