+ Reply to Thread
Results 1 to 5 of 5

How do I remove everything after the hyphen when the hyphen is sometimes the second hyphen

  1. #1
    Registered User
    Join Date
    08-11-2016
    Location
    New Jersey
    MS-Off Ver
    Professional Plus 2010
    Posts
    1

    How do I remove everything after the hyphen when the hyphen is sometimes the second hyphen

    We use a third party vendor to store and access our data. When running one key report it used to turn out a field of company names. We have a excel report that looks for their names in reports and counts them.

    Some of the names are BRCM, Community Resource Center, or Hemingwey's Place. But some have hyphens in the name like BR-Corp or NJ-State, which is alright because we set up the report to count them.

    Now the vendor has revamped their site and now that field produces both the company name and the contact name.
    So now the fields comes out as BCRM - Margaret Jones or BR-CORP - Sam Johnson.

    I can run a formula to get rid of the hyphen and everything after the hyphen but that would eliminate everything after the hyphen in name that naturally have the hyphen.

    So I would get BCRM AND BC, when I need BCRM and BR-CORP

    Other than yelling at my vendor, is there a formula to remove the hyphen and everything after only after a certain point and preserve entries where the hyphen should be there?

    Thanks

  2. #2
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,064

    Re: How do I remove everything after the hyphen when the hyphen is sometimes the second hy

    Can you provide some test data and expected results with

    1) hyphens in
    2) no hyphens if thats also what you get
    3) hyphens in if you have any data where the hyphens are to be left in
    Regards
    Special-K

    Ensure you describe your problem clearly, I have little time available to solve these problems and do not appreciate numerous changes to them.

  3. #3
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,207

    Re: How do I remove everything after the hyphen when the hyphen is sometimes the second hy

    Post a small sample file (not image) showing desired outcome.

    To upload a file click "Go Advanced" then scroll down to "Manage Attachments"

  4. #4
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: How do I remove everything after the hyphen when the hyphen is sometimes the second hy

    With company name in A2, this formula will do what you need.

    =TRIM(LEFT(A2,FIND("-",A2,IF(SUBSTITUTE(A2,"-"," ",2)=A2,1,FIND(A2,"-")+1))-1))
    Last edited by jason.b75; 08-11-2016 at 11:28 AM.

  5. #5
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,054

    Re: How do I remove everything after the hyphen when the hyphen is sometimes the second hy

    Hi there. This works:

    =LEFT(A1,FIND("|",SUBSTITUTE(A1,"-","|",LEN(A1)-LEN(SUBSTITUTE(A1,"-",""))))-1)
    Attached Files Attached Files
    Last edited by Glenn Kennedy; 08-11-2016 at 11:29 AM.
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

+ 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 leading zero's after hyphen
    By jprlimey in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-07-2016, 11:03 AM
  2. Remove numbers followed by hyphen in text column
    By grantman7 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-23-2015, 11:54 PM
  3. dont understand hyphen hyphen
    By pg300 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-30-2014, 12:42 AM
  4. How to keep hyphen in a string and remove all specific characters
    By SunOffice in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-27-2013, 12:32 AM
  5. Macro to remove hyphen from number
    By AZJimBird in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-22-2013, 03:19 AM
  6. Replies: 4
    Last Post: 03-02-2005, 12:06 PM
  7. [SOLVED] Need to remove hyphen in group of #s
    By [email protected] in forum Excel General
    Replies: 2
    Last Post: 03-02-2005, 11:06 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