excel-formula - 一个数字数组的总和,在 1 个单元格中用逗号分隔,仅当至少有 5 个元素时
问题描述
- 我需要同一单元格中元素数组的总和。
- 它们用逗号分隔。
- 如果有 <5 个元素,则不要计算该单元格的总和。
例子:
cell 1A: 2,1,2,3,1 cell 1B: 9 (the sum)
cell 2A: 1, 2 cell 2B: -- (nothing as there are less than five elements).
我试图解释自己。希望很清楚。
解决方案
我在这里问了一个类似的问题:
但是你有一个额外的要求,所以试试下面的用户定义函数:
Public Function SumWithin(s As String) As Variant
If s = "" Then
SumWithin = ""
Exit Function
End If
If InStr(1, s, ",") = 0 Then
SumWithin = ""
Exit Function
End If
arry = Split(s, ",")
If UBound(arry) < 4 Then
SumWithin = ""
Exit Function
End If
For Each a In arry
SumWithin = SumWithin + CDbl(a)
Next a
End Function
一些例子:
这种方法避免了典型的Text-to-Columns方法所需的所有额外单元格。没有 VBA也可以做到这一点,但它涉及到数组公式
。
推荐阅读
- c# - 使用 `x:Name` 和 ResourceDictionary.xaml.cs 生成“无法从 'Solution.Project.ResourceDictionary' 转换为 'Xamarin.Forms.Element'”错误
- sql - 保持更新记录的变化记录
- svg - gnuplot 在 svg 中有很多重复的条目
- r - RSelenium - 在后台启动服务器(不弹出窗口)
- python - 如果列包含列表中的子字符串,则使用从列表中删除的子字符串创建新列
- linux - Nginx : 将 httpS://....com:8080/ 重定向到 httpS://....com
- html - 如何使用 Selenium 验证登录文本框验证错误消息
- c - 当我访问微控制器中的内存值时,为什么它指向我的数据值的末尾?
- express - 更新现有的 mongodb 数据 MERN
- html - 如何配置我的 React 项目以从公共文件夹 html 文件中删除 .html 扩展名?