提取Excel不重復(fù)值的自定義函數(shù)方案,F(xiàn)unction MergerRepeat(Index As Integer, ParamArray arglist() As Variant)
---------------------------------------------
’時(shí)間:2008-12-26
’理整:宇 bengdeng
’功能:獲得指定單元格區(qū)域或數(shù)組中的不重復(fù)集合或值
’參數(shù)說明:
’Index:整型,當(dāng)值小于1時(shí),函數(shù)返回一個(gè)集合;
’ 大于1且小于不重復(fù)項(xiàng)的時(shí),返回一個(gè)不重復(fù)的值
’ 大于不重復(fù)項(xiàng)時(shí),返回空。
’arglist():可為單元格區(qū)域或數(shù)組常量。
----------------------------------------------
Dim NotRepeat As Object, tStr As String
Set NotRepeat = CreateObject("Scripting.Dictionary")
For Each arg In arglist
For Each rRan In arg
If TypeName(rRan) = "Range" Then
If rRan.Value <> "" Then NotRepeat(rRan.Value) = 0
Else
NotRepeat(rRan) = 0
End If
Next
Next
If Index < 1 Then
MergerRepeat = NotRepeat.keys
ElseIf Index <= NotRepeat.Count Then
arr = NotRepeat.keys
MergerRepeat = arr(Index - 1)
Else
MergerRepeat = ""
End If
End Function
下面用幾個(gè)應(yīng)用的實(shí)例,來說明該函數(shù)的應(yīng)用。
1、返回A1:A10中不重復(fù)值的個(gè)數(shù)。
=COUNTA(MergerRepeat(0,A1:A10))
2、在B列從B1格開始列出A1:A10的不重復(fù)數(shù)值。
在B1格設(shè)定公式:
=MergerRepeat(ROW(),$A$1:$A$10)
并向下填充。
3、求多個(gè)區(qū)域(可以不連續(xù))加數(shù)組的不重復(fù)個(gè)數(shù)。
=COUNTA(MergerRepeat(0,A1:A6,{"abc","Excel吧",1,"excelba.com"},C2:C6))
新聞熱點(diǎn)
疑難解答
圖片精選