excel - 使用 Sumifs 时类型不匹配(错误 13)
问题描述
我想添加 Q 列中所有单元格的值,这些单元格的日期在 Z 列中的现在和 30 分钟前之间,并且在 Y 列中具有特定名称。
dim nu as Date
dim ThirtyMinAgo as Date
dim currentBestTopThree as Integer
nu = WorksheetFunction.RoundDown(Now * 48, 0) / 48
ThirtyMinAgo = nu - 1 / 48
currentBestTopThree = _
Application.SumIfs(Sheets("topthreecheck").Range("Y2:Y" & Rows.Count).End(xlUp).Row, employeelist(i), _
Sheets("topthreecheck").Range("Z2:Z" & Rows.Count).End(xlUp).Row, "<" & nu, _
Sheets("topthreecheck").Range("Z2:Z" & Rows.Count).End(xlUp).Row, ">=" & ThirtyMinAgo, _
Sheets("topthreecheck").Range("Q2:Q" & Rows.Count).End(xlUp).Row)
employeelist(i)
是一个数组,其中包含 Y 列中的所有唯一名称。
i
是For
循环的当前迭代,在1 and Ubound(employeelist)
Z 列包含格式为“2020-03-01 08:32:23”的日期
Y 列包含名称
Q 列包含数字
SumIfs 行给了我错误
类型不匹配(错误 13)
我试图硬编码一个日期:
currentBestTopThree = Application.SumIfs(Sheets("topthreecheck").Range("Z2:Z" & Rows.Count).End(xlUp).Row, #2/25/2020 9:30:00 AM#, _
Sheets("topthreecheck").Range("Q2:Q" & Rows.Count).End(xlUp).Row)
但它仍然显示错误。
我也试过:
If Sheets("topthreecheck").Range("Z2") = #2/25/2020 9:30:00 AM# Then
End If
那行并没有给我类型不匹配错误。
有人知道这里发生了什么吗?
就好像代码试图对日期求和。我想这就是它给出错误的原因。因为currentBestTopThree
是整数。但我都试过了
SumIfs(Sum_range, Range1, Criteria1)
和
SumIfs(Range1, Criteria1, Sum_range)
其中之一应该是正确的!
解决方案
推荐阅读
- c# - C# WinForm DataGridView 单元格剪切区域
- java - 使 JPQL/QueryDSL 不会产生可怕的查询
- flutter - 颤振主题未应用于新屏幕
- c# - LINQ to Entities 仅支持无参数构造函数和初始化程序:Linq
- python - 在尊重重复排序键的相对顺序位置的同时在 Python 中对列表进行排序?
- python - 根据条件在 loc 中动态获取列
- django - 使用 Sphinxsearch 运行的 Django 引导表上的“未知参数”错误
- r - 如何随着时间的推移为传单()地图制作动画,而不仅仅是显示最新时间戳的颜色/数据
- swift - 带有 Swift 5.5 的 Xcode 13.0 将不再使用“import CreateML”语句构建我的项目,如何解决?
- python - pyodbc.OperationalError: ('HYT00', '[HYT00] [Microsoft][ODBC Driver 17 for SQL Server]登录超时已过期 (0) (SQLDriverConnect)')