|
楼主 |
发表于 2020-1-29 22:38
|
显示全部楼层
Sub xyz()
If MsgBox("选择二个以上单元格后单击,可以统计出可见单元格中不重复值的个数。(注意事项:不计筛选、隐藏,也不计空格、真空,但要统计换行符等非打印字符)", vbOKCancel + vbInformation, "功能说明:") <> vbOK Then Exit Sub
Dim myran As Range, myran2 As Range, mycoll As New Collection, i As Integer
On Error GoTo errline
Set myran = Application.InputBox("请选择待统计的单元格区域(任意)", "数据设置", , , , , , 8)
myran.Select
If myran.Count = 1 Then Exit Sub
On Error Resume Next
For Each myran2 In myran.SpecialCells(xlCellTypeVisible)
If Trim(myran2) <> "" Then
mycoll.Add myran2, Key:=CStr(myran2)
End If
Next
MsgBox "选区不重复值个数: " & mycoll.Count, , "计算结果:"
Set myran = Nothing
Set myran2 = Nothing
errline:
End Sub |
|