View Single Post
 
Old 03-09-2018, 09:37 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The following macro will count the unique occurrences of each character in a string thus
Lorem will have five unique characters and Lorem ipsum will have ten unique characters (including the space). mummy will have three unique characters.

Code:
Sub CountUniqueChars()
Dim Col As Collection
Dim oRng As Range
Dim i As Integer
    If Len(Selection.Range) > 0 Then
        Set oRng = Selection.Range
        Set Col = New Collection
        On Error Resume Next
        For i = 1 To Len(oRng)
            Col.Add Mid(oRng.Text, i, 1), Mid(oRng.Text, i, 1)
        Next i
        MsgBox Col.Count
    Else
        MsgBox "Nothing selected"
    End If
lbl_Exit:
    Set Col = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote