Function Count_Char(ResType As Integer, ParamArray Arr() As Variant)
'ResType: Dang ket qua
'ResType= -1 : Dem so ky tu cua chuoi so loai trung
'ResType= 0 : Chuoi so loai trung khong Sort
'ResType= 1 : Chuoi so loai trung Sort tu 0 -> 9
'ResType= 2 : Chuoi so loai trung Sort tu 9 -> 0
Dim i As Byte, iTem, S(0 To 9), Scheck(0 To 10)
For i = LBound(Arr) To UBound(Arr)
If TypeName(Arr(i)) = "Range" Or TypeName(Arr(i)) = "Variant()" Then
For Each iTem In Arr(i)
Call Update_S(ResType, iTem, S, Scheck)
Next
Else
Call Update_S(ResType, Arr(i), S, Scheck)
End If
If Scheck(10) = 10 Then Exit For
Next i
If ResType = -1 Then
Count_Char = Scheck(10)
Else
Count_Char = Join(S, Empty)
End If
End Function
Private Sub Update_S(ByVal ResType As Integer, ByVal iTem, ByRef S(), ByRef Scheck())
Dim i As Long, ik As Byte, tmp As String
For i = 1 To Len(iTem)
tmp = Mid(iTem, i, 1)
If IsNumeric(tmp) Then
ik = CByte(tmp)
If IsEmpty(Scheck(ik)) Then
If ResType = 0 Then
S(Scheck(10)) = ik
ElseIf ResType = 1 Then
S(ik) = ik
ElseIf ResType = 2 Then
S(9 - ik) = ik
End If
Scheck(ik) = True
Scheck(10) = Scheck(10) + 1
If Scheck(10) = 10 Then Exit Sub
End If
End If
Next i
End Sub