Removing Duplicate Words in a single Cell

eesterkin

New Member
Joined
Nov 20, 2013
Messages
15
Hi,

I've got the following product dimensions in a single cell:

[TABLE="width: 889"]
<tbody>[TR]
[TD="width: 889"]Small: 9'' H x Small: 3'' Dia x Medium: 9.5'' H x Medium: 4.25'' Dia x Large: 12'' H x Large: 4.25'' Dia

My goal is to only have the word Small listed once, Medium Once, Large Once...so it would look like
[/TD]
[/TR]
</tbody>[/TABLE]
Small: 9'' H x 3'' Dia x Medium: 9.5'' H x 4.25'' Dia x Large: 12'' H x 4.25'' Dia

I've tried using the following VBA:

Function RemoveDupes2(txt As String, Optional delim As String = " ") As String
Dim x
'Updateby20140924
With CreateObject("Scripting.Dictionary")
.CompareMode = vbTextCompare
For Each x In Split(txt, delim)
If Trim(x) <> "" And Not .exists(Trim(x)) Then .Add Trim(x), Nothing
Next
If .Count > 0 Then RemoveDupes2 = Join(.keys, delim)
End With
End Function

Problem is that it removes the "Dia" and other words since they are duplicate word as well.

Can anyone help me specify which duplicate words I want to remove using a formula or VBA?

Thank you!
 
Last edited:

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Thank you so much! It does give me the value I requested...now I'm seeing that I made an error...rather than

Small: 9'' H x 3'' Dia x Medium: 9.5'' H x 4.25'' Dia x Large: 12'' H x 4.25'' Dia

I need it to look like

Small: 9'' H x 3'' Dia Medium: 9.5'' H x 4.25'' Dia Large: 12'' H x 4.25'' Dia

ie. just take out those "x" before the sizes. Sorry about this...any help you can offer is much appreciated!
 
Upvote 0
Thank you so much! It does give me the value I requested...now I'm seeing that I made an error...rather than

Small: 9'' H x 3'' Dia x Medium: 9.5'' H x 4.25'' Dia x Large: 12'' H x 4.25'' Dia

I need it to look like

Small: 9'' H x 3'' Dia Medium: 9.5'' H x 4.25'' Dia Large: 12'' H x 4.25'' Dia

ie. just take out those "x" before the sizes. Sorry about this...any help you can offer is much appreciated!
You are welcome.

You want to remove all the x's? Your example shows only the first x removed.
 
Upvote 0
Hi...just the x's before the next size

Small: 9'' H x 3'' Dia Medium: 9.5'' H x 4.25'' Dia Large: 12'' H x 4.25'' Dia

So the x between dimensions stays...but the x before "Medium" is removed.
 
Upvote 0
Nevermind...I used your Substitute formula to get it to work!

Thanks again for your help...spent hours trying to figure this out!!!
 
Upvote 0

Forum statistics

Threads
1,222,905
Messages
6,168,948
Members
452,227
Latest member
sam1121

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