'This macro counts the number of unique values in a range and
'displays a message with the result
'Copyright, Andrés González, 2008
Sub contarunicos()
Dim matriz()
SizeRango = Selection.Count
ReDim matriz(SizeRango)
'matriz(pos) = rango(pos, 1)
ocurrencia = 0
celdas = 0
ultima = 1
For Each celda In Selection
For cont = 1 To ultima
If celda.Value = matriz(cont) Then
ocurrencia = "si"
Else
garbage = 1
End If
Next cont
If ocurrencia = "si" Then
ultima = ultima
Else
matriz(ultima) = celda.Value
ultima = ultima + 1
End If
ocurrencia = 0
Next
MsgBox ("There are " & ultima - 1 & " unique values")
End Sub
No comments:
Post a Comment