excel vba 统计 A列不同个数怎么做?

别用=Application.SUMPRODUCT(1/COUNTIF(A:A,A:A))套用,因为数据量太大,用这个直接就卡死了!

正常情况是,在一个项目中,可以在遍历数据时,顺便计算数目,
可以用字典法,也可以用数组法。追问

大哥给我写写吧,一定好好追加!

追答Public Sub 计数()

    Dim CXrng As Range, d, i As Long

    Set d = CreateObject("Scripting.Dictionary")

    For Each CXrng In Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)

        If CXrng.Value <> "" And Not d.Exists(CXrng.Value) Then

            d(CXrng.Value) = ""

            i = i + 1

        End If

    Next

    MsgBox i 'I 是不重复个数

End Sub

温馨提示:答案为网友推荐,仅供参考
相似回答