excel - 如何对数字序列的第一个数字求和
问题描述
以下数字从单元格 B5 开始: 23 34 45 56 45 54 我想将每个数字的第一个数字相加,并在单元格 C9 中显示结果
我尝试对下面的代码进行不同的调整。
Sub sum_first_digit()
Dim colnum As Integer
Dim sumfirst As Integer
sumfirst = 0
For colnum = 2 To 7 Step 1
cellref = Cells(5, colnum)
sumfirst = sumfirst + (Left(celref, 1))
Next colnum
Range("C9").Value = sumfirst
End Sub
预计单元格 C9 的编号为 23。
实际是
运行时错误 13:类型不匹配
解决方案
我不知道为什么公式不起作用。在 C9 使用中,
=SUMPRODUCT(--LEFT(B5:G5&0))
'an array formula that will skip over blank and text cells
=SUM(IFERROR(--LEFT(B5:G5&0), 0))
推荐阅读
- c++ - 如何从 C++ 中的基类调用派生类的虚函数
- java - 将泛型参数扩展到 Java 函数
- r - RStudio - 更改选项卡中的空格数
- r - 采用十六进制颜色并返回具有 RGB 值和可能的 alpha 通道值的命名向量的函数
- python - 为什么当我运行我的代码时,我没有得到关于我正在抓取的网页的信息?
- ruby-on-rails - 设计:与登录用户不同时忘记密码流程
- mono - MVC 应用程序的环境变量在 VS2019 Mac 中运行
- java - 为什么我从 Firebase 得到 NULL 结果
- sql-server - 如何设置 GCP Cloud SQL 实例以信任 Active Directory 域以进行 Windows 身份验证?
- scala - 将列值列表传递给火花数据框作为新列