decadence
Well-known Member
- Joined
- Oct 9, 2015
- Messages
- 525
- Office Version
- 365
- 2016
- 2013
- 2010
- 2007
- Platform
- Windows
Hi, I am trying to remove duplicate letters from cells, however the code below works fine on letters but when there are numbers involved it doesn't end well. What I would like to do is remove all duplicate letters from a cell even if there are numbers present. Can someone help with this.
Example:
From This..
[TABLE="class: grid, width: 250"]
<tbody>[TR]
[TD]CC1, CC32, CC33, CC18
[/TD]
[/TR]
[TR]
[TD]RR7
[/TD]
[/TR]
[TR]
[TD]DD123 DD54_2
[/TD]
[/TR]
</tbody>[/TABLE]
To This..
[TABLE="class: grid, width: 250"]
<tbody>[TR]
[TD]C1, C32, C33, C18
[/TD]
[/TR]
[TR]
[TD]R7
[/TD]
[/TR]
[TR]
[TD]D123 D54_2
[/TD]
[/TR]
</tbody>[/TABLE]
Code:
Sub LetterDupes()
Dim Str As String, xChar As String, MyStr As String, x As range, Rng As range
Set xDic = CreateObject("Scripting.Dictionary")
Set Rng = ActiveSheet.UsedRange
For Each x In Rng
Str = x
For i = 1 To VBA.Len(Str)
xChar = VBA.Mid(Str, i, 1)
If xDic.Exists(xChar) Then
Else
xDic(xChar) = ""
MyStr = MyStr & xChar
End If
Next
Next x
Rng = MyStr
End Sub
Example:
From This..
[TABLE="class: grid, width: 250"]
<tbody>[TR]
[TD]CC1, CC32, CC33, CC18
[/TD]
[/TR]
[TR]
[TD]RR7
[/TD]
[/TR]
[TR]
[TD]DD123 DD54_2
[/TD]
[/TR]
</tbody>[/TABLE]
To This..
[TABLE="class: grid, width: 250"]
<tbody>[TR]
[TD]C1, C32, C33, C18
[/TD]
[/TR]
[TR]
[TD]R7
[/TD]
[/TR]
[TR]
[TD]D123 D54_2
[/TD]
[/TR]
</tbody>[/TABLE]
Last edited: