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..
<tbody>
</tbody>
To This..
<tbody>
</tbody>
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..
CC1, CC32, CC33, CC18 |
RR7 |
DD123 DD54_2 |
<tbody>
</tbody>
To This..
C1, C32, C33, C18 |
R7 |
D123 D54_2 |
<tbody>
</tbody>
Last edited: