Find Duplicate Instances in one cell from List of Target Phrases

jsturm

New Member
Joined
Sep 27, 2018
Messages
11
I have a list of terms in one sheet (Find List)

I have a column of text data "Replace Data" in another sheet that I need to search for exact full words/phrases in the Find List and if multiple instances exist in the text data of Replace Data, I need to eliminate all instances of that exact/full word or phrase except for the first instance.

Find List Term
I find terms

Replace Data Text
Joe, you have to believe I find terms and will without a doubt I find terms.

Result Desired
Joe, you have to believe I find terms and will without a doubt .
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Some clarification.

1. Replace Data Text can have punctuation (the example has "," and ".")
Can Find List Term also have punctuation or not?

2. Please confirm the Result desired for this scenario

Find List Term
I find terms
Mike is well
Joe you have

Replace Data Text
Joe, you have to believe I find terms and will without a doubt I find terms but Joe you have to believe me.

3. Please confirm the Result desired for this scenario

Find List Term
I find terms
Mike is well
Joe

Replace Data Text
Joe, you have to believe I find terms and will without a doubt I find terms Joe.

4. Please confirm the Result desired for this scenario

Find List Term
I find terms
Joe

Replace Data Text
Joe, you have to believe I find terms.

5. Please confirm the Result desired for this scenario

Find List Term
Find Terms

Replace Data Text
Joe, you have to believe I find terms and will without a doubt I find terms.
 
Upvote 0
Some clarification.

1. Replace Data Text can have punctuation (the example has "," and ".")
Can Find List Term also have punctuation or not?
Yes there may be punctuation in both but not standard delimiters. The punctuation must be a perfect match to trigger matching/eliminated a duplicate term.

2. Please confirm the Result desired for this scenario

Find List Term
I find terms
Mike is well
Joe you have

Replace Data Text
Joe, you have to believe I find terms and will without a doubt I find terms but Joe you have to believe me.

Result: Joe, you have to believe I find terms and will without a doubt but Joe you have to believe me.

3. Please confirm the Result desired for this scenario

Find List Term
I find terms
Mike is well
Joe

Replace Data Text
Joe, you have to believe I find terms and will without a doubt I find terms Joe.

Result: Joe, you have to believe I find terms and will without a
doubt .

4. Please confirm the Result desired for this scenario

Find List Term
I find terms
Joe

Replace Data Text
Joe, you have to believe I find terms.

Result: Joe, you have to believe I find terms.

5. Please confirm the Result desired for this scenario

Find List Term
Find Terms

Replace Data Text
Joe, you have to believe I find terms and will without a doubt I find terms.

Result: Joe, you have to believe I find terms and will without a doubt I find terms.

Thanks Peter_SSs!
Replied with info in Bold in quote above. Let me know any further questions.
 
Upvote 0
OK, so
- capitalisation must also match.
- punctuation must match. I think this will be tricky. To confirm, what about these?

6. Please confirm the Result desired for this scenario

Find List Term
Tom

Replace Data Text
I like Tom and Tom's cat
Sue likes Tom and I like Tom, and his cat
Sue likes Tom. I like Tom.
Do you like Tom? I like Tom.
 
Last edited:
Upvote 0
OK, so
- capitalisation must also match.
- punctuation must match. I think this will be tricky. To confirm, what about these?

6. Please confirm the Result desired for this scenario

Find List Term
Tom

Replace Data Text
I like Tom and Tom's cat
Sue likes Tom and I like Tom, and his cat
Sue likes Tom. I like Tom.
Do you like Tom? I like Tom.

Result: I am assuming each line is a separate cell here.
I like Tom and 's cat
Sue likes Tom and I like , and his cat
Sue likes Tom. I like .
Do you like Tom? I like .

Yes, looking for exact matches including punctuation and caps. However it can/needs be partial string replace. I know they will be exact matches because I am already running a match/replace loop to get from many different related terms down to fewer of these standardized terms (Tom or Thomas or Thom or Tomas all change to Tom) first. Then this step I am inquire about will reduce down to get rid of all of the duplicates that mean the same thing but make the length of the cell excessive.

The Find/Replace code works very well now- perhaps a tweak is possible to change matches for each term after the first match inside the same cell as "" instead of a whole new Macro to call upon in the process.
I am a novice so any ideas are welcome.

Here is the current code that does the initial changing of many terms down to fewer standardized terms.



Sub FindReplaceJobTitleSkills()


If (MsgBox("Do you want to continue find & replacement. Make sure you have backup of this file.", vbYesNo, "Message") = vbNo) Then
Exit Sub
End If

Dim myDataSheet As Worksheet
Dim myReplaceSheet As Worksheet
Dim myLastRow As Long
Dim myRow As Long
Dim myFind As String
Dim myReplace As String

' Specify name of Data sheet
Set myDataSheet = Sheets("Processed Compilation Tab")

' Specify name of Sheet with list of replacements
Set myReplaceSheet = Sheets("Job Title Append")

' Assuming list of replacement start in column A on row 2, find last entry in list
myLastRow = myReplaceSheet.Cells(Rows.Count, "A").End(xlUp).Row

Application.ScreenUpdating = False
myReplaceSheet.Activate
' Loop through all list of replacments
For myRow = 2 To myLastRow
' Get find and replace values (from columns A and B)
myFind = myReplaceSheet.Cells(myRow, "B")
myReplace = myReplaceSheet.Cells(myRow, "C")
' Start at top of data sheet and do replacements
myDataSheet.Activate
Range("A1").Select
' Ignore errors that result from finding no matches
On Error Resume Next
' Do all replacements on column A of data sheet
myDataSheet.Columns("A:A").Replace What:=myFind, Replacement:=myReplace, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _
ReplaceFormat:=False

myDataSheet.Columns("B:B").Replace What:=myFind, Replacement:=myReplace, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _
ReplaceFormat:=False


myDataSheet.Columns("I:I").Replace What:=myFind, Replacement:=myReplace, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _
ReplaceFormat:=False
Application.StatusBar = myRow & "" & myLastRow
' Reset error checking
On Error GoTo 0
Next myRow

Application.ScreenUpdating = True

MsgBox "Replacements complete!"

End Sub
 
Upvote 0
I'm sorry, I haven't been able to spend time on the forum for a while and that will continue for a while longer.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,239
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top