简体   繁体   中英

Find What & Replace With: MS Excel Find and Replace Multiple Characters within a Cell Using Two Columns

I've attempted using both the INDEX and MATCH, as well as. the SUBSTITUTE formula, both are great, but unfortunately neither are allows me to achieve the desired outcome and each has limitations. Using MS Excel, In Cell A2 I have a text that contains multiple characters and letters that I want to replace within the string (Example A2: {Mr. and Mrs.} John Peterson_Jones {444} 585/0000). I also have two (2) additonal Columns each with Headings (Cell B1: "Find What" and Cell C1: "Replace With"). In Column B2:B101 (Find What), I have a list of individual key words, letters and characters that if any of the specific keyword(s), letter(s) or character(s) are found in Cell A2; are to be replaced with the adjacent Find What - REPLACE WITH keyword, letter or charcters in the Replace With column C2:C101.

Old Text: {Mr. and Mrs.} John Peterson_Jones @ {444} 585/0000 New Text: Mr. & Mrs. John Peterson-Jones

Find {, }, @, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Replace With Blank Value Find "and" = Replace With "&" Find "_" = Replace With -(hyphen) Find "/" = Replace With -(hyphen)

If you can use a macro then you could do something like this:

For i = 2 To 101

    findThese = Split(Range("B" & i), ",")
    replaceWith = Range("C" & i).Value
    replaceWith = Trim(replaceWith)

    If Not IsEmpty(findThese) Then
        For Each found In findThese
            found = Trim(found)
            Range("A2").Replace What:=found, Replacement:=replaceWith, LookAt:=xlPart, _
                SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
                ReplaceFormat:=False
        Next
    Else
        findThis = Range("B" & i).Value
        Range("A2").Replace What:=findThis, Replacement:=replaceWith, LookAt:=xlPart, _
                SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
                ReplaceFormat:=False
    End If
Next i

I assumed you meant this: spreadsheet http://www.piombo.com/ebay/spreadsheet.jpg

What you want to do may just be faster using the "find and replace" feature (ctrl+f) rather than using a formula. The problem with the formulas in excel s they are cell specific, not character specific. In order to do what you want with a formula you are looking are a plethora of nested if statements that would take quite a while to write.

The other option you could do is text to columns, but the columns after this column should need to be empty or it will over write the values.

Select the column->Data Tab->Text to columns-> delimited-> Check the other box with '@' in the box. This wont fix the names, but will move all the phone numbers to another column to be mass deleted. Once you remove the numbers and @ sign, you just have to replace the brackets and underscores.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM