分享

提取Excel不重复值的自定义函数方案

 mountaineer 2010-05-31
提取Excel不重复值的自定义函数方案,Function MergerRepeat(Index As Integer, ParamArray arglist() As Variant)
---------------------------------------------
’时间:2008-12-26
’理整:宇 bengdeng
’功能:获得指定单元格区域或数组中的不重复集合或值
’参数说明:
’Index:整型,当值小于1时,函数返回一个集合;
’    大于1且小于不重复项的时,返回一个不重复的值
’    大于不重复项时,返回空。
’arglist():可为单元格区域或数组常量。
----------------------------------------------
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

下面用几个应用的实例,来说明该函数的应用。

1、返回A1:A10中不重复值的个数。

=COUNTA(MergerRepeat(0,A1:A10))

2、在B列从B1格开始列出A1:A10的不重复数值。

在B1格设定公式:

=MergerRepeat(ROW(),$A$1:$A$10)

并向下填充。

3、求多个区域(可以不连续)加数组的不重复个数。

=COUNTA(MergerRepeat(0,A1:A6,{"abc","Excel吧",1,"excelba.com"},C2:C6))
 
本文来自-编程入门网:http://www./office/excel/201002/14987.htm

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多