当前位置:网站首页>Excel·VBA自定义函数获取单元格多数值
Excel·VBA自定义函数获取单元格多数值
2022-04-23 10:57:00 【薛定谔_51】
《excel吧提问-单元格多数值》,返回多个单元格中出现最多次数的单元格的值
适用多个单元格和单元格区域
Function majority(ParamArray args())
'函数定义majority(单元格1,单元格2,...)返回多个单元格出现次数最多的单元格的值
Dim a, aa, t, i, k, v, m, x, dict As Object, result
Set dict = CreateObject("scripting.dictionary")
For Each a In args
If Not IsArray(a) Then
t = a.Value
dict(t) = dict(t) + 1
Else
For Each aa In a
t = aa.Value
dict(t) = dict(t) + 1
Next
End If
Next
k = dict.keys
v = dict.Items
m = WorksheetFunction.Max(v) '最多次数
result = Array()
For i = 0 To dict.count - 1: '遍历字典
If v(i) = m Then
x = UBound(result) + 1
ReDim Preserve result(x)
result(x) = k(i)
End If
Next
majority = Join(result, ",")
End Function
举例
版权声明
本文为[薛定谔_51]所创,转载请带上原文链接,感谢
https://blog.csdn.net/hhhhh_51/article/details/124349720
边栏推荐
猜你喜欢
随机推荐
MBA-day5数学-应用题-工程问题
vm设置静态虚拟机
MySQL how to merge the same data in the same table
Linked list intersection (linked list)
SQL server query database deadlock
精彩回顾 | DEEPNOVA x Iceberg Meetup Online《基于Iceberg打造实时数据湖》
Intuitive understanding entropy
Data analysis learning (I) data analysis and numpy Foundation
ID number verification system based on visual structure - Raspberry implementation
Special members and magic methods
How to bind a process to a specified CPU
Hikvision face to face summary
Source insight 4.0 FAQs
The difference between restful and soap
Read integrity monitoring techniques for vision navigation systems
Leetcode22: bracket generation
SSH uses private key to connect to server without key
Mba-day6 logic - hypothetical reasoning exercises
Contact between domain name and IP address
主流手机分辨率与尺寸