08/12/21 16:06:47
>>172
矩形範囲の種類を数える高速なワークシート関数なんてない。
1列とか1行でソートされてるとかなら簡単だが、矩形範囲ならユーザー定義関数作れ。
Dictionaryオブジェクトの方が簡単だが、>>176の書いてるCollectionを使うなら
Function CountKinds(r As Range) As Long
Dim col As Collection
Dim element As Variant
Dim cnt As Long
Set col = New Collection
On Error Resume Next
For Each element In r.Value
If Not IsEmpty(element) Then
col.Add Empty, CStr(element)
If Err.Number = 0 Then
cnt = cnt + 1
Else
Err.Clear
End If
End If
Next
CountKinds = cnt
End Function
一次元配列に移してからソートして数える方法もあるが。