+ Reply to Thread
Results 1 to 9 of 9

How to remove text after the last -

  1. #1
    Forum Contributor
    Join Date
    08-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2007, MS 365 (Windows 10 Pro 64-bit)
    Posts
    810

    How to remove text after the last -

    Hi,
    Please help me with Formula how to remove the text after the last "-"

    I've tried this but not working "=LEFT(A2,LEN(A2)-FIND("-",A2))"


    Input Output
    A013-ECO-15-88 A013-ECO-15
    A013-ECO15-881 A013-ECO15
    A013 ECO15-882 A013 ECO15
    A013 ECO15 A013 ECO15
    A013-ECO16 A013

    Regards,
    tt3
    Last edited by tuongtu3; 02-17-2019 at 04:15 AM.

  2. #2
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: How to remove text after the last -

    Text at A1

    Please try at B1
    =TRIM(LEFT(SUBSTITUTE(A1,"-",REPT(" ",20),MAX(1,LEN(A1)-LEN(SUBSTITUTE(A1,"-","")))),20))

  3. #3
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: How to remove text after the last -

    Another approach...
    =LEFT(A1,FIND("@",SUBSTITUTE(A1,"-","@",LEN(A1)-LEN(SUBSTITUTE(A1,"-",""))))-1)
    copied down
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  4. #4
    Forum Contributor
    Join Date
    08-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2007, MS 365 (Windows 10 Pro 64-bit)
    Posts
    810

    Re: How to remove text after the last -

    Hi Thank you very much for yur help
    @Bo_Ry: Work
    @FDibbins: get error on this line ==> A013 ECO15 got #VALUE!


    Thanks Again
    Regards,
    tt3

  5. #5
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: How to remove text after the last -

    Quote Originally Posted by tuongtu3 View Post
    ...
    @FDibbins: get error on this line ==> A013 ECO15 got #VALUE!...
    Your request was to return text before the last -
    That example (which I did not test - my fault) does not contain any -
    Try this...
    =IFERROR(LEFT(A1,FIND("@",SUBSTITUTE(A1,"-","@",LEN(A1)-LEN(SUBSTITUTE(A1,"-",""))))-1),A1)

  6. #6
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: How to remove text after the last -

    TT3, Happy to help

    You may add Iferror on Ford's formula.
    =iferror(LEFT(A1,FIND("@",SUBSTITUTE(A1,"-","@",LEN(A1)-LEN(SUBSTITUTE(A1,"-",""))))-1),a1)

  7. #7
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: How to remove text after the last -

    Thank Bo_Ry

  8. #8
    Forum Contributor
    Join Date
    08-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2007, MS 365 (Windows 10 Pro 64-bit)
    Posts
    810

    Re: How to remove text after the last -

    Thank you and now both formula are working good.

    Regards,
    tt3

  9. #9
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: How to remove text after the last -

    Happy to help 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] Remove Blanc Space, parse text, convert text to measurement
    By plans in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-25-2015, 07:50 PM
  2. Replies: 3
    Last Post: 06-15-2014, 11:31 AM
  3. Remove quotes in text file after converting Excel to Text in VBA Access 2002
    By ucalcen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-13-2014, 10:35 AM
  4. [SOLVED] Search text in cells, find matching text based on list, remove all but one entry
    By adam_mc in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-30-2013, 12:50 PM
  5. Remove all text after 1st comma and Remove the -,NE and spacing
    By Tan Bee Hock in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-06-2008, 06:28 AM
  6. Replies: 1
    Last Post: 04-18-2005, 05:06 PM
  7. Replies: 1
    Last Post: 04-17-2005, 08:10 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