当前位置:网站首页>Excel · VBA custom function to obtain multiple cell values
Excel · VBA custom function to obtain multiple cell values
2022-04-23 11:01:00 【Schrodinger_ fifty-one】
《excel Let's ask questions - Cell multi value 》, Returns the value of the cell that appears the most times in multiple cells
Applicable to multiple cells and cell ranges
Function majority(ParamArray args())
' Function definition majority( Cell 1, Cell 2,...) Returns the value of the cell with the most occurrences of multiple cells
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) ' Most times
result = Array()
For i = 0 To dict.count - 1: ' Ergodic dictionary
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
give an example
版权声明
本文为[Schrodinger_ fifty-one]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231056567131.html
边栏推荐
- MBA-day5数学-应用题-工程问题
- Full stack cross compilation x86 completion process experience sharing
- Anaconda3 installation
- How to use JDBC callablestatement The wasnull () method is called to check whether the value of the last out parameter is SQL null
- Esp32 learning - use and configuration of GPIO
- 全栈交叉编译X86完成过程经验分享
- 闹钟场景识别
- Read integrity monitoring techniques for vision navigation systems - 4 multiple faults in vision system
- Swagger2 接口如何导入Postman
- 【leetcode】199. Right view of binary tree
猜你喜欢
随机推荐
MBA-day6 逻辑学-假言推理练习题
SQL Server cursor circular table data
How to quickly download vscode
比深度学习更值得信赖的模型ART
Solution architect's small bag - 5 types of architecture diagrams
The courses bought at a high price are open! PHPer data sharing
图像处理——噪声小记
Jupyter Lab 十大高生产力插件
Manjaro installation and configuration (vscode, wechat, beautification, input method)
Code implementation of general bubbling, selection, insertion, hill and quick sorting
Is the pointer symbol of C language close to variable type or variable name?
Ueditor -- limitation of 4m size of image upload component
Mba-day5 Mathematics - application problems - engineering problems
数据库管理软件SQLPro for SQLite for Mac 2022.30
More reliable model art than deep learning
The difference between restful and soap
Diary of dishes | Blue Bridge Cup - hexadecimal to octal (hand torn version) with hexadecimal conversion notes
vm设置静态虚拟机
如何使用JDBC CallableStatement.wasNull()方法调用来查看最后一个OUT参数的值是否为 SQL NULL
@valid,@Validated 的学习笔记