+ Reply to Thread
Results 1 to 9 of 9

remove all characters to right of "-" character, including "-"

  1. #1
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,173

    remove all characters to right of "-" character, including "-"

    I have a list if ~60,000 zip codes in column T. Example as follows:
    90025
    10022-3556
    12456
    50223
    60036-9944
    77533-6655
    34775

    I need remove all the characters to the right of the "-' character, including the "-". The desired output is as follows:
    90025
    10022
    12456
    50223
    60036
    77533
    34775


    I could use this formula in column U, but I need to leave the structure of the file intact. Is there a way to do this with VBA? Thanks
    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: remove all characters to right of "-" character, including "-"

    Try =IF(ISERROR(LEFT(T2,FIND("-",T2)-1)),T2,LEFT(A1,FIND("-",T2)-1))

    I wasn't sure if you are using 2003 or 2007 +, so my formula is based on Excel 2003 version

  3. #3
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: remove all characters to right of "-" character, including "-"

    Hi maacmaac,

    select the data, press Ctrl + H and replace -* with blank (nothing).. thanks.

    Regards,
    DILIPandey

    <click on below 'star' if this helps>
    DILIPandey, Excel rMVP
    +919810929744 (India), +971528225509 (Dubai), [email protected]

  4. #4
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: remove all characters to right of "-" character, including "-"

    Wouldn't it be just: =IF(LEN(T2)>5,LEFT(T2,5),T2) and then Copy Paste Special values on top of the T column and delete the formula column entries.
    Last edited by Cutter; 04-27-2012 at 02:39 PM. Reason: Added IF() to formula

  5. #5
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: remove all characters to right of "-" character, including "-"

    Please Login or Register  to view this content.

  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,258

    Re: remove all characters to right of "-" character, including "-"

    Hello maacmaac,

    Here is a flexible and fast VBA solution to your ZIP code problem. The range is automatically sized and read into an array. The array values are modified using Regular Expressions. The modified array is then copied back into the range.
    Please Login or Register  to view this content.
    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!)

  7. #7
    Forum Contributor
    Join Date
    02-07-2012
    Location
    MIA
    MS-Off Ver
    Excel 2007, 2010
    Posts
    429

    Re: remove all characters to right of "-" character, including "-"

    This should work:

    Please Login or Register  to view this content.
    I hope it helps.
    Last edited by Pichingualas; 04-27-2012 at 02:44 PM.
    .?*??)
    `?.???.?*??)?.?*?)
    (?.?? (?.?
    Pichingualas <---
    ??????????????????????????

    Wrap your code with CODE TAGS.
    Thank those who helped you, Don't forget to add to their REPUTATION!!! (click on the star below their post).
    Please mark your threads as [SOLVED] when they are (Thread Tools->Mark thread as Solved).

  8. #8
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: remove all characters to right of "-" character, including "-"

    Hi maacmaac
    Another approach
    Please Login or Register  to view this content.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  9. #9
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: remove all characters to right of "-" character, including "-"

    As DILIPandey suggested, but using VBA. (Change column reference as needed.)
    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)

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