+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Registered User
    Join Date
    06-04-2009
    Location
    Virginia
    MS-Off Ver
    Excel 2007
    Posts
    8

    Replacing Misspelled sub-string in varying full string

    I have a situation where a word (in this case "Restaurant") is misspelled in a list of about 78,000 location names. The location names are in one column, and the [misspelled] word "Restaurant" is anywhere between the first word of the string, to the last, with any amount of alphanumeric/symbol characters between. For example:

    Alice's Restaurant
    Alli's Restaurant & Bar
    Alexis Restaurant of Waukesha
    Amigo's Mexican Restaurant #2

    I want to replace any misspellings of the word with correct, but since the list is so long, and the way the word is misspelled varies so much, going through manually is entirely too time-consuming.

    Some of the variations I've seen so far are Resta, Restau, Restaur, Restuara, etc...

    Is there a way to search and replace cells that contain the text in any location of the string? Specifically, where ever there is JUST "Restau", replace with "Restaurant", regardless of where it is in the string? This way, trailing text is not deleted or manipulated, i.e. "Alice's Restaur and Bar" will change to "Alice's Restaurant and Bar".

    There are many misspelled words in this list, but the most ubiquitous is Restaurant, so any help with this would be extremely helpful. Thanks.
    Attached Files Attached Files
    Last edited by freerdj; 08-27-2009 at 05:43 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    MS Office Excel 2007
    Posts
    698

    Re: Replacing Misspelled sub-string in varying full string

    Spell checker under Review tab?
    Regards
    Special-K

    I rarely return to a problem once I've answered it so make sure you clearly define what the trouble is.

  3. #3
    Forum Moderator NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003, 2007, 2010
    Posts
    31,163

    Re: Replacing Misspelled sub-string in varying full string

    Try this to replace anything that starts with "Rest" with "Restaurant"

    =REPLACE(A1,SEARCH("Rest",A1),SEARCH(" ",MID(A1,SEARCH("Rest",A1),255))-1,"Restaurant")

    adjust A1 to suit your original string
    Microsoft MVP - Excel

    Where there is a will there are many ways. Pick One!


    Please read the Forum Rules

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

    Preferred Charities: Lupus Canada and Sick Kids Foundation.
    Feel Free to Donate if you want to, for the assistance you received today.

  4. #4
    Forum Moderator NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003, 2007, 2010
    Posts
    31,163

    Re: Replacing Misspelled sub-string in varying full string

    Quote Originally Posted by Special-K View Post
    Spell checker under Review tab?
    Restaurant wasn't offered when checking Restau and other trimmings...
    Microsoft MVP - Excel

    Where there is a will there are many ways. Pick One!


    Please read the Forum Rules

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

    Preferred Charities: Lupus Canada and Sick Kids Foundation.
    Feel Free to Donate if you want to, for the assistance you received today.

  5. #5
    Forum Moderator shg's Avatar
    Join Date
    06-21-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007
    Posts
    25,137

    Re: Replacing Misspelled sub-string in varying full string

    You could use a UDF.
    Code:
           ------------A------------ --------------B--------------- C -----D----- ---E---
       1   Location Title            Correction                       Restaurant  BStoria
       2   Astoria Restaruant Inc    BStoria Restaurant Inc           Resta       Astoria
       3   Beauvais Caribbean Restau Beauvais Caribbean Restaurant    Restaraunt         
       4   Bedford Springs Resort    Bedford Springs Resort           Restaruant         
       5   Beijing Restaruant        Beijing Restaurant               Restau             
       6   Bella Luna Pizzeria Resta Bella Luna Pizzeria Restaurant   Restauarant        
       7   Bernardo's Mexican Resta  Bernardo's Mexican Restaurant    Restauarnt         
       8   Bershes Family Restauarnt Bershes Family Restaurant        Restaur            
       9   Billy Joes Restaraunt     Billy Joes Restaurant            Restaurnte         
      10   Blue Jeans Lounge & Resta Blue Jeans Lounge & Restaurant                      
      11   Boothbay Harbor Inn Resta Boothbay Harbor Inn Restaurant
    The D:E range at right has the correct spelling in the top row, and misspellings below for all the words you want to correct. Col E changes Astoria to BStoria just as an example. You can make the range as wide as needed.

    The formula in B2 and down is

    =WordSubstitute(A2, $D$1:$E$9)

    The UDF is
    Code:
    Function WordSubstitute(ByVal sInp As String, r As Range)
        ' The top row of r contains replacement words for the words below
        
        Dim rCol        As Range
        Dim cell        As Range
        Dim sFind       As String
        Dim sRepl       As String
    
        sInp = " " & WorksheetFunction.Trim(sInp) & " "
    
        For Each rCol In r.Offset(1).Resize(r.Rows.Count - 1).Columns
            sRepl = " " & rCol.Cells(0).Text & " "
    
            For Each cell In rCol.Cells
                sFind = " " & cell.Text & " "
                If Len(Trim$(sFind)) = 0 Then Exit For
    
                If InStr(1, sInp, sFind, vbTextCompare) Then
                    sInp = Replace$(sInp, sFind, sRepl, , , vbTextCompare)
                    Exit For
                End If
            Next cell
        Next rCol
    
        WordSubstitute = Mid$(sInp, 2, Len(sInp) - 2)
    End Function
    Last edited by shg; 08-29-2009 at 04:05 PM. Reason: renamed, tweaked
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Registered User
    Join Date
    06-04-2009
    Location
    Virginia
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Replacing Misspelled sub-string in varying full string

    Quote Originally Posted by NBVC View Post
    Try this to replace anything that starts with "Rest" with "Restaurant"

    =REPLACE(A1,SEARCH("Rest",A1),SEARCH(" ",MID(A1,SEARCH("Rest",A1),255))-1,"Restaurant")

    adjust A1 to suit your original string

    I intentionally misspelled my cell to "Cozumel Mexican Restarant" and applied the function to it and it returned a value error.

  7. #7
    Forum Moderator NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003, 2007, 2010
    Posts
    31,163

    Re: Replacing Misspelled sub-string in varying full string

    Quote Originally Posted by freerdj View Post
    I intentionally misspelled my cell to "Cozumel Mexican Restarant" and applied the function to it and it returned a value error.
    Sorry...didn't account for it being the last word...

    Try:

    =REPLACE(A1,SEARCH("Rest",A1),SEARCH(" ",MID(A1,SEARCH("Rest",A1),255)&" ")-1,"Restaurant")
    Microsoft MVP - Excel

    Where there is a will there are many ways. Pick One!


    Please read the Forum Rules

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

    Preferred Charities: Lupus Canada and Sick Kids Foundation.
    Feel Free to Donate if you want to, for the assistance you received today.

  8. #8
    Registered User
    Join Date
    06-04-2009
    Location
    Virginia
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Replacing Misspelled sub-string in varying full string

    Quote Originally Posted by NBVC View Post
    Sorry...didn't account for it being the last word...

    Try:

    =REPLACE(A1,SEARCH("Rest",A1),SEARCH(" ",MID(A1,SEARCH("Rest",A1),255)&" ")-1,"Restaurant")

    The misspell is not always the last word; will this function apply to other variations as well?

    shg --> I will apply the UDF and try shortly

  9. #9
    Forum Moderator NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003, 2007, 2010
    Posts
    31,163

    Re: Replacing Misspelled sub-string in varying full string

    Quote Originally Posted by freerdj View Post
    The misspell is not always the last word; will this function apply to other variations as well?
    Yes, it will work as long as the part string "Rest" or "rest" is there.
    Microsoft MVP - Excel

    Where there is a will there are many ways. Pick One!


    Please read the Forum Rules

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

    Preferred Charities: Lupus Canada and Sick Kids Foundation.
    Feel Free to Donate if you want to, for the assistance you received today.

  10. #10
    Registered User
    Join Date
    06-04-2009
    Location
    Virginia
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Replacing Misspelled sub-string in varying full string

    Quote Originally Posted by NBVC View Post
    Yes, it will work as long as the part string "Rest" or "rest" is there.
    I wish you could somehow see the excitement and cheers that are flowing through our office right now.

    This will save us days of manual searching since we can apply it elsewhere.

    Thank you SO much.

    And thank you shg for the UDF

  11. #11
    Forum Moderator NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003, 2007, 2010
    Posts
    31,163

    Re: Replacing Misspelled sub-string in varying full string

    You are welcome...

    ...Note that this is not 100% foolproof...

    If you have a spelling like Ristorante then it will not get fixed...
    Microsoft MVP - Excel

    Where there is a will there are many ways. Pick One!


    Please read the Forum Rules

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

    Preferred Charities: Lupus Canada and Sick Kids Foundation.
    Feel Free to Donate if you want to, for the assistance you received today.

  12. #12
    Forum Moderator NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003, 2007, 2010
    Posts
    31,163

    Re: Replacing Misspelled sub-string in varying full string

    If this might be the case, then after you applied the 1st phase, copy that new column and paste special, selecting Values, over the original or over itself (remember to maintain a backup in case of disaster)... Then apply formula like

    =IF(ISNUMBER(SEARCH("Rist",A1)),REPLACE(A1,SEARCH("Rist",A1),SEARCH(" ",MID(A1,SEARCH("Rist",A1),255)&" ")-1,"Restaurant"),A1)

    this will leave the correct ones alone and fix the ones with Rist in it...

    You can repeat this again and again to get any subtleties you may encounter...
    Microsoft MVP - Excel

    Where there is a will there are many ways. Pick One!


    Please read the Forum Rules

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

    Preferred Charities: Lupus Canada and Sick Kids Foundation.
    Feel Free to Donate if you want to, for the assistance you received today.

  13. #13
    Registered User
    Join Date
    06-04-2009
    Location
    Virginia
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Replacing Misspelled sub-string in varying full string

    Quote Originally Posted by NBVC View Post
    If this might be the case, then after you applied the 1st phase, copy that new column and paste special, selecting Values, over the original or over itself (remember to maintain a backup in case of disaster)... Then apply formula like

    =IF(ISNUMBER(SEARCH("Rist",A1)),REPLACE(A1,SEARCH("Rist",A1),SEARCH(" ",MID(A1,SEARCH("Rist",A1),255)&" ")-1,"Restaurant"),A1)

    this will leave the correct ones alone and fix the ones with Rist in it...

    You can repeat this again and again to get any subtleties you may encounter...

    Understood. There are several incorrect versions of "Grill", "Family", "Lounge", "Country Club", etc...

    Although there's no way I could duplicate this function combo, I do understand that search of "Rest" and replacement of "Restaurant" where found.

    Thanks again, so much.

  14. #14
    Forum Moderator NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003, 2007, 2010
    Posts
    31,163

    Re: Replacing Misspelled sub-string in varying full string

    Maybe shg's UDF is something to look into.. I am sure you can expand the D:E columns to include more fixes and other words....

    so in D1, you have Restaurant and below all possible mispellings, in E1, you have Grill and below all possible misspellings, in F1 you have Lounge and below... well, you get it..

    and then adjust Formula: =ReSpell(A2, $D$1:$E$9) to the full range of words to check for and corrections..
    Microsoft MVP - Excel

    Where there is a will there are many ways. Pick One!


    Please read the Forum Rules

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

    Preferred Charities: Lupus Canada and Sick Kids Foundation.
    Feel Free to Donate if you want to, for the assistance you received today.

  15. #15
    Registered User
    Join Date
    06-04-2009
    Location
    Virginia
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Replacing Misspelled sub-string in varying full string

    The difference is that I'd have to know all possible misspells of each word in order to correct them, and I'm always discovering new ones.

    The function you provided at least lets me ensure most of the word is searched for.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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.2.0