Help to remove specific named duplicate word from a cell

Cruiser69

Board Regular
Joined
Mar 12, 2018
Messages
68
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: 4

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
to create in a different cell use
=LEFT(E2,(FIND("TO INCLUDE ",E2,1)+10)) & SUBSTITUTE(MID(E2, (FIND("TO INCLUDE ",E2,1)+10), LEN(E2)),"TO INCLUDE ","")
 
Upvote 0
Thanks for your quick reply.
This is just what I needed.

Would there be a way to incorporate this into vba.

If not, this will be fine.
.
Regards,

Graham
 
Upvote 0
I think it just need substitute changing to replace to work in VBA

and find changing to instr
 
Upvote 0
if str contains the whole string

Left(str, InStr(1, str, "TO INCLUDE") + 10) + Replace(Mid(str, InStr(1, str, "TO INCLUDE") + 10, Len(str)), "TO INCLUDE ", "")
 
Upvote 0
Hi again.

This works well with merged cells, but if it is a single item I get an #VALUE
Is there an easy fix for this.
1693836252942.png


I would like to try the vba approach, but I'm not sure how to add it to a module.


Regards,

Graham.
 
Upvote 0
to get rid of the #Value
IFERROR(LEFT(E2,(FIND("TO INCLUDE ",E2,1)+10)) & SUBSTITUTE(MID(E2, (FIND("TO INCLUDE ",E2,1)+10), LEN(E2)),"TO INCLUDE ",""),E2)
 
Upvote 0
Solution
the below is quick and dirty but does what you need

VBA Code:
Sub removestring()

Dim str As String, str1 As String

' make sure your on the correct sheet in excel
' sheets("Sheetname").select
Sheets("Sheet1").Select
Range("E2").Select
Do While ActiveCell <> ""

str = ActiveCell.Value
If InStr(1, str, "TO INCLUDE") > 0 Then
str1 = Left(str, InStr(1, str, "TO INCLUDE") + 10) + Replace(Mid(str, InStr(1, str, "TO INCLUDE") + 10, Len(str)), "TO INCLUDE ", "")
str1 = Mid(str, InStr(1, str, "TO INCLUDE") + 10, Len(str))
' add new string to sheet in column F if it inclues search string - TO INCLUDE
ActiveCell.Offset(0, 1) = str1
Else
' add original string to sheet in column F if it doesnt inclues search string - TO INCLUDE
ActiveCell.Offset(0, 1) = str
End If
' move to next cell down
ActiveCell.Offset(1, 0).Select
Loop
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

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