简体   繁体   English

VBA代码中的类型不匹配错误

[英]Type mismatch error in VBA code

Hey guys i am trying to search a column of dates and count how many fall between two dates. 大家好,我想搜索一列日期并计算两个日期之间有多少个日期。 I get an error Type mismatch when i run it. 运行它时出现错误类型不匹配。

Dim iVal As Integer
iVal = Application.WorksheetFunction.CountIfs("Incident_stats!k:k", ">=" & B1, "Incident_stats!k:k", "<=" & B2)
Range("D1").Value = iVal

Countifs requires Range objects, not address strings: Countifs需要Range对象,而不是地址字符串:

iVal = Application.WorksheetFunction.CountIfs(Range("Incident_stats!k:k"), ">=" & Range("B1"), Range("Incident_stats!k:k"), "<=" & Range("B2"))

I assumed the B1 and B2 were cells too, rather than variables. 我假设B1和B2也是单元格,而不是变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM