+ Reply to Thread
Results 1 to 13 of 13

Remove Certain Last Words from String

  1. #1
    Forum Contributor
    Join Date
    07-13-2007
    Posts
    151

    Remove Certain Last Words from String

    I'm attempting to extract the Street Names from an Address.

    For Example, if given "123 Very Big Street" I'd want to extract "Very Big".

    If given, "123 Very Big" I'd want the same answer.

    I've written code to do this, with a simple IF statement to identify mathcing last words like "Street" and "Drive".

    How can I efficiently do this with a large list of last words? I'm drawing a blank on how to query against an array that would contain all these values.

    Thanks,

    Shred

    Please Login or Register  to view this content.

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834
    Deleted...
    Last edited by jindon; 02-16-2008 at 01:45 AM.

  3. #3
    Forum Contributor
    Join Date
    07-13-2007
    Posts
    151
    What I was getting at is having about 50 or so strings to match against.

    Street, Drive, Way, Lane, road, rd., st., Blvd., Avenue, Ave, etc.

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    You might want to put the list of final words in a dynamic named range, so it can be added to.

    Code like this could be used for the test.
    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834
    Edited
    You don't seem to be happy with the UDF, so I delete.
    Last edited by jindon; 02-16-2008 at 01:19 AM.

  6. #6
    Forum Contributor
    Join Date
    07-13-2007
    Posts
    151

    mikerickson

    Thanks for the reply.

    I'm trying to keep the maintenance of the list of lastwords out of the user's hands. I want to keep it in the code. Either way, I have to type the values somewhere.

    I was thinking I could somehow populate an array with the values, and then loop through them to see if I have a match with the curent string.

    I guess I could hide the worksheet the dynamic range list is on.

    Any other ideas?

    Thanks,

    Shred

  7. #7
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    An array would work. Since MATCH works with arrays, you could avoid looping. Match is also case insensitive.

    Please Login or Register  to view this content.
    Last edited by mikerickson; 02-16-2008 at 11:02 AM.

  8. #8
    Forum Contributor
    Join Date
    07-13-2007
    Posts
    151
    Thanks Mikerickson. That's the kind of thing I was envisioning. I had made similar attempts but never quite got my syntax correct I guess.

    Thanks for pointing out that MATCH is is not case sensitive. It looks like this will do the trick for me.

    Shred

  9. #9
    Forum Contributor
    Join Date
    07-13-2007
    Posts
    151

    Jindon

    Wasn't unhappy...just didn't click with me. Maybe it was way over my head.

    Thanks for replying.

  10. #10
    Forum Contributor
    Join Date
    07-13-2007
    Posts
    151

    Solution Found

    Thanks Mikerickson for pointing me in this direction. I adapted your ideas into some code that eventually worked. I was unable to get the results I desired using ISNUMERIC when there was not a match as an error would be returned by the Match worksheet function; that worked fine if is there was a match between the lastword and the list of choices. So I resorted to ISERROR instead and got the results I needed. It now works whether there is a match or not.

    I also got it working with a dynamic range pulled from the workbook ('commented line)

    See code below.

    Thanks again.

    Please Login or Register  to view this content.

  11. #11
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    You don't need both the named range and the array. Managing this list would be much easier using only one or the other, but not both. It sounds like you would prefer the array.

  12. #12
    Forum Contributor
    Join Date
    07-13-2007
    Posts
    151
    Correct. I was testing both methods. I prefer the array and maintaining the list in the code for this particular application.

  13. #13
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834
    =Foox(A1,B1:B100) As String
    where B1:B100 has a list of surfix
    Please Login or Register  to view this content.
    Last edited by jindon; 02-18-2008 at 03:51 AM.

+ 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