+ Reply to Thread
Results 1 to 6 of 6

Trim trailing CR/LF character(s) off of string variable

  1. #1
    Registered User
    Join Date
    02-20-2012
    Location
    Chicago, Illinois
    MS-Off Ver
    Excel 2010
    Posts
    25

    Trim trailing CR/LF character(s) off of string variable

    Hello!

    I've spent way too much time trying to figure out this simple thing. Doh! I have a text string that may have one or more CR and/or LF characters on the right. Unfortunately, RTrim doesn't remove CR/LF characters.

    Is there an easy way to do something similar to the following that will remove the CR/LF characters?

    Please Login or Register  to view this content.
    Thank you

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Trim trailing CR/LF character(s) off of string variable

    Try this:

    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    02-20-2012
    Location
    Chicago, Illinois
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Trim trailing CR/LF character(s) off of string variable

    Thank you 6StringJazzer! Worked like a champ.

    Ciao!

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Trim trailing CR/LF character(s) off of string variable

    You're welcome! Thanks for the rep, and thanks for marking your thread Solved!

  5. #5
    Registered User
    Join Date
    02-20-2012
    Location
    Chicago, Illinois
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Trim trailing CR/LF character(s) off of string variable

    Sorry to Unsolve this! After doing some testing, I noticed that the code suggested by the ever-helpful 6StringJazzer removes ALL CR and/or LF characters from my string.

    I need to limit the removal to just any/all *trailing* CR and/or LF characters on the right-hand end of the string. Just like the RTrim function works with trailing spaces.

    I'm thinking I may have to setup a loop, starting at the end of the length of the string.... [scurries off to the dev lab]

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Trim trailing CR/LF character(s) off of string variable

    One way to do it is a loop, lopping off the last character as long as it's a match for CR or LF. Another method would be to use regex.

    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. Replies: 2
    Last Post: 12-02-2013, 03:29 PM
  2. Replies: 3
    Last Post: 04-17-2010, 05:02 AM
  3. Trying to trim a trailing space char and the Trim function isn't working
    By Psychochook in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-30-2007, 11:28 PM
  4. [SOLVED] Need better understanding of TRIM so I can get rid of trailing spa
    By Tom Q in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 AM
  5. Need better understanding of TRIM so I can get rid of trailing spa
    By Tom Q in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 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