|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Function ZQMODE(rgData As Range, varMax As Variant, varType As Variant) As Variant
- Dim arr As Variant, lngRow As Long
- Dim objDic As Object
- Dim lngCount As Long, lngMax As Long
- Dim arrKeys As Variant, arrItems As Variant
- Dim lngVal As Long, strLastVal As String, lngR As Long
- Dim strResult As String, intDisplay As Integer, lngIndex As Long
- Dim arrResult As Variant, lngID As Long
-
- Set objDic = CreateObject("Scripting.Dictionary")
- arr = rgData
- ReDim arrResult(LBound(arr) To UBound(arr), 1 To 1) As String
-
- lngMax = varMax
- intDisplay = varType
-
- If lngMax < 3 Then Exit Function
- If intDisplay <> 0 And intDisplay <> 1 Then Exit Function
-
- For lngRow = LBound(arr) To UBound(arr)
- If arr(lngRow, 1) <> "" Then
- lngCount = lngCount + 1
- objDic(arr(lngRow, 1)) = objDic(arr(lngRow, 1)) + 1
- End If
-
- If lngCount = lngMax Then
- lngIndex = lngIndex + 1
- If objDic.Count = lngMax Then
- strResult = "9"
- Else
- arrKeys = objDic.keys
- arrItems = objDic.items
- lngVal = arrItems(LBound(arrItems))
- strResult = arrKeys(LBound(arrKeys))
- For lngR = LBound(arrItems) + 1 To UBound(arrItems)
- If arrItems(lngR) > lngVal Then
- lngVal = arrItems(lngR)
- strResult = arrKeys(lngR)
- ElseIf arrItems(lngR) = lngVal Then
- If arrKeys(lngR) = strLastVal Then
- lngVal = arrItems(lngR)
- strResult = arrKeys(lngR)
- End If
- End If
- Next
- End If
- lngCount = 0
- objDic.RemoveAll
-
- If intDisplay = 1 Then
- lngID = lngRow
- Else
- lngID = lngIndex
- End If
-
- arrResult(lngID, 1) = strResult
- strLastVal = strResult
- End If
-
- Next
-
- Set objDic = Nothing
- ZQMODE = arrResult
- End Function
复制代码 |
评分
-
1
查看全部评分
-
|