+ Reply to Thread
Results 1 to 13 of 13

Delete last break at the end of cell's contents.

  1. #1
    Forum Contributor
    Join Date
    07-01-2009
    Location
    Maine, USA
    MS-Off Ver
    Excel 2016
    Posts
    161

    Delete last break at the end of cell's contents.

    I have a column with multiple cells. The cells contain text. At the end of some of the cells, there is an unneeded break (there may be other breaks in the cell, but I'm only concerned with the last one). I would like a script to be able to delete this.

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Delete last break at the end of cell's contents.

    Can you post sample of your file?
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  3. #3
    Forum Contributor
    Join Date
    07-01-2009
    Location
    Maine, USA
    MS-Off Ver
    Excel 2016
    Posts
    161

    Re: Delete last break at the end of cell's contents.

    I would like to be able to select a cell or column (such as 'article description') and if there is a carriage return (think it chr(10)) at the end, delete it. There may be other carriage returns within the cell, but I only want the last one deleted.

    Capture.PNG

  4. #4
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Delete last break at the end of cell's contents.

    To be sure there is no confusion please attach an Excel sample showning the origunal data and the final result you need
    - Battle without fear gives no glory - Just try

  5. #5
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Delete last break at the end of cell's contents.

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

  6. #6
    Forum Contributor
    Join Date
    07-01-2009
    Location
    Maine, USA
    MS-Off Ver
    Excel 2016
    Posts
    161

    Re: Delete last break at the end of cell's contents.

    Yasser - your script did not work. Not only that, but it requires everything to be in B1:B100. I need it to be based on a selection (cell or column).

    PCI - attached is a sample of the file. The actual is much larger (columns and rows deleted)
    Attached Files Attached Files
    Last edited by mainemojo; 03-14-2018 at 04:22 PM.

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Delete last break at the end of cell's contents.

    Hi MaineMojo - for this to work there must be a selection

    Please Login or Register  to view this content.
    *Per Yassir's suggestion
    Last edited by xladept; 03-14-2018 at 05:03 PM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  8. #8
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Delete last break at the end of cell's contents.

    Hello my friend
    What about using the line in that way
    Please Login or Register  to view this content.

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

    Re: Delete last break at the end of cell's contents.

    mainemojo,

    This should do
    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    07-01-2009
    Location
    Maine, USA
    MS-Off Ver
    Excel 2016
    Posts
    161

    Re: Delete last break at the end of cell's contents.

    xladept - yours works the best because it works with a single cell selection or a row/column selection without any modifications (the other suggestions are based on specific columns, but would need to be modified if I wanted to do anything other than column 'B').

    With your script, if I select one cell, it's perfect. If I select a column or row, then I get a "runtime error '5':" - "invalid procedure call or arguement" error even though it does what it's supposed to. I'm assuming that this is because there is no defined boundry to the selection?
    Last edited by mainemojo; 03-19-2018 at 12:30 PM.

  11. #11
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Delete last break at the end of cell's contents.

    Try this:

    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    07-01-2009
    Location
    Maine, USA
    MS-Off Ver
    Excel 2016
    Posts
    161

    Re: Delete last break at the end of cell's contents.

    Perfect! Thank you!

  13. #13
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Delete last break at the end of cell's contents.

    You're welcome and thanks for the rep!

+ 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] Delete contents of a cell in a given range if it matches contents of a specific cell
    By rcicconetti in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-13-2016, 06:46 AM
  2. Delete Rows that contain matching cell contents in column to the contents in cell B1
    By sspatriots in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-23-2015, 05:39 PM
  3. [SOLVED] Macro Delete Contents in 23rd corresponding cell if the cell in range is a non-blank cell
    By murtaza.khan in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-04-2014, 01:11 AM
  4. How do I delete the contents in a cell, every other row?
    By ninj5 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-22-2013, 05:49 PM
  5. Delete cell contents
    By jsomer2000 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-13-2011, 08:38 AM
  6. merged cell's contents cut off beyond page break
    By 8thWonder in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-12-2009, 10:52 AM
  7. Delete contents of a cell
    By knighttrader in forum Excel General
    Replies: 2
    Last Post: 07-25-2008, 11:59 AM

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