+ Reply to Thread
Results 1 to 10 of 10

Removing a set of unwanted characters from a column

  1. #1
    Registered User
    Join Date
    01-02-2012
    Location
    Melbourne
    MS-Off Ver
    Excel 2003
    Posts
    63

    Removing a set of unwanted characters from a column

    Hi All

    I am trying to remove some superfluous text from a list of names.

    ie.
    current: John Brown (AUS), Joe Bloggs (NZ), Sue Smith nz., Ruby Red New Zealand
    desired: John Brown, Joe Bloggs, Sue Smith, Ruby Red.

    http://i.imgur.com/qLmCyAE.png

    In column E of the sample list, ive tried to account for all of these possibilities.

    The list of text to remove is quite long (longer than the sample in column E), so i was hoping there was a formula(s) or macro that would assist me rather that having to individually 'Find & Replace'.

    If anyone can assist, that would be great.

    Thanks!
    Attached Files Attached Files
    Last edited by Rob8489; 07-21-2013 at 09:23 PM. Reason: forgot attachement

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Removing a set of unwanted characters from a column

    Maybe like this
    if there maybe no match wrap in if/isna()
    =IF(ISNA(LOOKUP(2^15,SEARCH($E$2:$E$17,$A2),$E$2:$E$17)),$A2,TRIM(SUBSTITUTE($A2,LOOKUP(2^15,SEARCH($E$2:$E$17,$A2),$E$2:$E$17),"")))
    Attached Files Attached Files
    Last edited by martindwilson; 07-21-2013 at 09:34 PM.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Valued Forum Contributor
    Join Date
    05-20-2013
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2013
    Posts
    941

    Re: Removing a set of unwanted characters from a column

    If the names are always first and last only separated by a space, i.e. no middle names or initials, no prefixes, no suffixes,... and the superflous text is always separated with a space, the following will work.

    =LEFT(A2,FIND(" ",A2,FIND(" ",A2)+1)-1)

  4. #4
    Registered User
    Join Date
    01-02-2012
    Location
    Melbourne
    MS-Off Ver
    Excel 2003
    Posts
    63

    Re: Removing a set of unwanted characters from a column

    Quote Originally Posted by martindwilson View Post
    Maybe like this
    if there maybe no match wrap in if/isna()
    =IF(ISNA(LOOKUP(2^15,SEARCH($E$2:$E$17,$A2),$E$2:$E$17)),$A2,TRIM(SUBSTITUTE($A2,LOOKUP(2^15,SEARCH($E$2:$E$17,$A2),$E$2:$E$17),"")))
    Hi Martin

    that was extremely helpful, but i seem to be struggling when I apply to my own list of data

    I've attached another sample, could you tell me what I am doing wrong? My desired text isnt getting picked up. Is there a limit to how large your list(s) can be?

    Thanks again Martin
    Attached Files Attached Files

  5. #5
    Valued Forum Contributor
    Join Date
    05-20-2013
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2013
    Posts
    941

    Re: Removing a set of unwanted characters from a column

    In cell B10 of your 2nd file...

    =LEFT(A10,SMALL(IFERROR(SEARCH($E$10:$E$341,A10),LEN(A10)),1))

    ... and enter as an array formula (Ctrl+Shift+Enter), then fill/copy down.

    Also, it appears some of the text you may want to remove is not in your list, e.g. " !".

    If you make your list a dynamically-expanding named range, you can substitute its name for $E$10:$E$341 in the formula, and not have to change the formula every time you add to the list.

    [ETA] PS: this formula "assumes" the text to remain is always to the left of the text to remove.
    Last edited by jhren; 07-22-2013 at 04:46 AM.

  6. #6
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Removing a set of unwanted characters from a column

    im in bed!

  7. #7
    Registered User
    Join Date
    01-02-2012
    Location
    Melbourne
    MS-Off Ver
    Excel 2003
    Posts
    63

    Re: Removing a set of unwanted characters from a column

    Quote Originally Posted by jhren View Post
    In cell B10 of your 2nd file...

    =LEFT(A10,SMALL(IFERROR(SEARCH($E$10:$E$341,A10),LEN(A10)),1))

    ... and enter as an array formula (Ctrl+Shift+Enter), then fill/copy down.

    Also, it appears some of the text you may want to remove is not in your list, e.g. " !".

    If you make your list a dynamically-expanding named range, you can substitute its name for $E$10:$E$341 in the formula, and not have to change the formula every time you add to the list.

    [ETA] PS: this formula "assumes" the text to remain is always to the left of the text to remove.
    thanks for that jhren, the tips certainly helped but im still tripping on something and its eaten up my whole damn night and im ready to give up.

    Would you be kind enough to look at it and find out why the formula isn't picking up every unwanted ?

    In this updated sample list, the formula isnt picking up the text " (australia) pty ltd !" (which i have highlighted in red in the worksheet so its easy to see), but the problem is that it is only removing the "pty ltd !" part of the cell, and leaving the "(australia)" part behind.

    In the unwanted list i also have "pty ltd !" down as an item, and it works fine on that. So maybe it is the parentheses? ive got no idea.

    Any guidance would greatly help me in not going mad

    Thanks !
    Attached Files Attached Files

  8. #8
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Removing a set of unwanted characters from a column

    ok why it fails
    11th hour group (australia) pty ltd ! contains both (australia) pty ltd ! and pty ltd ! so both are found trouble is the lookup will only act on the last one it finds in the list
    so make sure column e has a leading and trailing space
    use len(e2) filled down in col f to get the length of each string
    sort col e:f by f smallest to largest there must be no blanks any where in the range in column e that includes the end
    Attached Files Attached Files

  9. #9
    Valued Forum Contributor
    Join Date
    05-20-2013
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2013
    Posts
    941

    Re: Removing a set of unwanted characters from a column

    Quote Originally Posted by Rob8489 View Post
    thanks for that jhren, the tips certainly helped but im still tripping on something and its eaten up my whole damn night and im ready to give up.

    Would you be kind enough to look at it and find out why the formula isn't picking up every unwanted ?

    In this updated sample list, the formula isnt picking up the text " (australia) pty ltd !" (which i have highlighted in red in the worksheet so its easy to see), but the problem is that it is only removing the "pty ltd !" part of the cell, and leaving the "(australia)" part behind.

    In the unwanted list i also have "pty ltd !" down as an item, and it works fine on that. So maybe it is the parentheses? ive got no idea.

    Any guidance would greatly help me in not going mad

    Thanks !
    You're not using my formula in your sample. Unlike Martin's formula, mine essentially searches the entire list for the one with the most characters to remove.

    In the attached, I converted the list to a Table, added list from previous example and removed duplicates and sorted. The advantage of using a Table is that you can use a structured reference in the formula (meaning you don't have to change it every time you modify the list... similar to a dynamic named range), and it automatically includes new entries at the bottom (you'll see a lightning bolt menu icon which provides options to not expand and stop expanding automatically... just don't use either).

    I then used a modified version of my [array] formula...
    Attached Files Attached Files

  10. #10
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Removing a set of unwanted characters from a column

    AAA aways avoid arrays! lol
    edit the original was proposed as op indicates that they used 2003 i didnt notice the xlsx til later and agree a table helps here
    Last edited by martindwilson; 07-24-2013 at 07:38 AM.

  11. #11
    Registered User
    Join Date
    01-02-2012
    Location
    Melbourne
    MS-Off Ver
    Excel 2003
    Posts
    63

    Re: Removing a set of unwanted characters from a column

    you're both geniuses! thank you!

+ 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. Removing Unwanted Characters & Moving Others
    By bdb1974 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-10-2009, 10:09 AM
  2. removing unwanted characters
    By djbetterly in forum Excel General
    Replies: 4
    Last Post: 05-06-2008, 12:22 PM
  3. Removing unwanted characters
    By Richard in forum Excel General
    Replies: 2
    Last Post: 06-23-2006, 02:40 PM
  4. Removing unwanted characters
    By jermsalerms in forum Excel General
    Replies: 15
    Last Post: 01-19-2006, 05:20 PM
  5. Removing unwanted characters
    By Scorpvin in forum Excel General
    Replies: 8
    Last Post: 12-05-2005, 05:10 PM

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