Help to remove specific named duplicate word from a cell

Cruiser69

Board Regular
Joined
Mar 12, 2018
Messages
61
Office Version
  1. 365
Platform
  1. Windows
Hi all.
I have searched everywhere I can and cannot find an answer.
Below is an example of what I am trying to achieve.
When multiple items are scanned into a sale sheet I run a macro which merges them together.
I want to remove the multiple "TO INCLUDE" words, just leaving the first instance as in Row 7.
The normal remove duplicates will remove all duplicate words, but as there are multiple sideboards as in the example, it would remove those as well.



1693829421971.png


Any help will be appreciated.

Regards,

Graham
 

Attachments

  • 1693828926306.png
    1693828926306.png
    20.7 KB · Views: 3
It may not matter to you but the earlier formula puts a double space in the text in the first two results.
In any case, here is a simpler formula that I think also does the job required
Excel Formula:
=LET(ti," TO INCLUDE",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(E2,ti," #",1),ti,"")," #",ti))

.. and the equivalent vba
VBA Code:
Sub ReduceToInclude()
  With Range("E2", Range("E" & Rows.Count).End(xlUp))
    .Offset(, 1).Value = Evaluate("LET(ti,"" TO INCLUDE"",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(" & .Address & ",ti,"" #"",1),ti,""""),"" #"",ti))")
  End With
End Sub
 
Upvote 0

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
It may not matter to you but the earlier formula puts a double space in the text in the first two results.
In any case, here is a simpler formula that I think also does the job required
Excel Formula:
=LET(ti," TO INCLUDE",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(E2,ti," #",1),ti,"")," #",ti))

.. and the equivalent vba
VBA Code:
Sub ReduceToInclude()
  With Range("E2", Range("E" & Rows.Count).End(xlUp))
    .Offset(, 1).Value = Evaluate("LET(ti,"" TO INCLUDE"",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(" & .Address & ",ti,"" #"",1),ti,""""),"" #"",ti))")
  End With
End Sub
Thanks Peter.

I'll have a look.

Regards,

Graham
 
Upvote 0

Forum statistics

Threads
1,215,092
Messages
6,123,064
Members
449,090
Latest member
fragment

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