当前位置:网站首页>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
边栏推荐
- 微信小程序简介、发展史、小程序的优点、申请账号、开发工具、初识wxml文件和wxss文件
- 主流手机分辨率与尺寸
- Understand the key points of complement
- 第六站神京门户-------手机号码的转换
- MBA-day6 逻辑学-假言推理练习题
- 比深度学习更值得信赖的模型ART
- Idea - indexing or scanning files to index every time you start
- Dirichlet prefix sum (number theory optimization formula sub complexity weapon)
- VScode
- RESTful和SOAP的区别
猜你喜欢

JVM - common parameters

Swagger2 接口如何导入Postman

Solution architect's small bag - 5 types of architecture diagrams

Chapter 120 SQL function round

Swagger2 自定义参数注解如何不显示

Solutions to common problems in visualization (VIII) solutions to problems in shared drawing area

Notes on concurrent programming of vegetables (IX) asynchronous IO to realize concurrent crawler acceleration

Ueditor -- limitation of 4m size of image upload component

Manjaro installation and configuration (vscode, wechat, beautification, input method)

C语言之结构体(进阶篇)
随机推荐
JVM - common parameters
MBA-day5数学-应用题-工程问题
Dirichlet prefix sum (number theory optimization formula sub complexity weapon)
SQL Server 递归查询上下级
景联文科技—专业数据标注公司和智能数据标注平台
Simple thoughts on the design of a microblog database
Visual common drawing (I) stacking diagram
vm设置静态虚拟机
Gets the current time in character format
Notes on concurrent programming of vegetables (V) thread safety and lock solution
Xshell+Xftp 下载安装步骤
Derivation and regularization
Embedded related surface (I)
【leetcode】199. Right view of binary tree
Charles 功能介绍和使用教程
微信小程序简介、发展史、小程序的优点、申请账号、开发工具、初识wxml文件和wxss文件
Diary of dishes | Blue Bridge Cup - hexadecimal to octal (hand torn version) with hexadecimal conversion notes
关于JUC三大常用辅助类
Mba-day6 logic - hypothetical reasoning exercises
Idea - indexing or scanning files to index every time you start