• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

remove duplicate characters in one cell

J.Steik

New Member
Hello and thank you for the chance to ask for help - I am having a tough time here..I am trying to reference just the last 4 non-repeating digits in one cell. A user will input their account number in a userform I create and I want to have only the last 4 non-repeating digits appear on a cell on Worksheet2. I think the logical step wpuld be to eliminate all duplicate numbers in the account number, then use the RIGHT(TEXT, 4) function.. I apologize in advance for asking something which is likely simple to the other members here, but I am stumped.

Thank you
 
the file uploaded is titled "example" and shows basically what I would *like* to see as far as input on Sheet1 in A2, and the desired result in Sheet 2, A2. I would like to be able to remove all duplicate digits from the data input in Sheet 1, A2 and display only the last 4 digits remaining of those results. I hope that helps clarify - if not please feel free to give me advice! Thank you so much!
 

Attachments

  • example.xlsm
    9.6 KB · Views: 17
UDF
Use in cell like
=UniqLast4(Sheet1!A2)
Code:
Function UniqLast4(ByVal txt As String)
    With CreateObject("VBScript.RegExp")
        .Pattern = "(.*)(\d)(.*)(\2)(.*)"
        Do While (.test(txt)) * (Len(txt) > 4)
            txt = .Replace(txt, "$1$3$4$5")
        Loop
        UniqLast4 = Right$(txt, 4)
    End With
End Function
 
Back
Top