excel错误1004无法获取工作表函数类的countifs属性出现

时间:2016-05-17 06:09:46

标签: excel vba excel-vba

你好,我真的希望有人可以帮助我。 我想使用3个标准在VBA中使用countifs并具有此脚本

Sub Count()
Dim DateSmall As Date
Dim DateBig As Date
Dim Company As String


DateSmall = CDate(Sheet2.Range("C28"))
DateBig = CDate(Sheet2.Range("E28"))
Company = Sheet2.Range("B28").Value


Set rGo = Sheet1.Range("E10", Sheet1.Range("E" & Rows.Count).End(xlUp))
Set rCompany = Sheet1.Range("C10", Sheet1.Range("C" & Rows.Count).End(xlUp))

CountIn = Application.WorksheetFunction.CountIfs(rGo, ">=" & DateSmall, rGo, "<=" & DateBig, rCompany, Company)


MsgBox CountIn

End Sub

但是它有错误1004但是当我使用相同的脚本使用2个标准时我可以使用2个标准的脚本

Sub Count()
Dim DateSmall As Date
Dim DateBig As Date



DateSmall = CDate(Sheet2.Range("C28"))
DateBig = CDate(Sheet2.Range("E28"))


Set rGo = Sheet1.Range("E10", Sheet1.Range("E" & Rows.Count).End(xlUp))

CountIn = Application.WorksheetFunction.CountIfs(rGo, ">=" & DateSmall, rGo, "<=" & DateBig)


MsgBox CountIn

End Sub

我希望someona可以帮助我。 。

Sheet 1
02-Oct-14   SSI
02-Oct-14   SSI
02-Oct-14   SSI
03-Oct-14   SSI
03-Oct-14   SSI
03-Oct-14   SSI
07-Oct-14   SSI
07-Oct-14   SSI
07-Oct-14   SCI
03-Oct-14   SSI
06-Oct-14   SSI
06-Oct-14   SSI
06-Oct-14   SSI
06-Oct-14   SSI
06-Oct-14   SSI
03-Oct-14   SSI
07-Oct-14   SCI
02-Oct-14   JSU
02-Oct-14   JSU
30-Sep-14   JSU

Sheet 2
SSI     1-Jan-14        10-Jan-16

2 个答案:

答案 0 :(得分:1)

我认为原因是rGO和rCompany的范围不同。

重要信息:每个附加范围必须与criteria_range1参数具有相同的行数和列数。范围不必彼此相邻。

有关详细信息,请参阅 https://support.office.com/en-us/article/COUNTIFS-function-dda3dc6e-f74e-4aee-88bc-aa8c2a866842

希望这有帮助。

答案 1 :(得分:-1)

Sheet 1
02-Oct-14   SSI
02-Oct-14   SSI
02-Oct-14   SSI
03-Oct-14   SSI
03-Oct-14   SSI
03-Oct-14   SSI
07-Oct-14   SSI
07-Oct-14   SSI
07-Oct-14   SCI
03-Oct-14   SSI
06-Oct-14   SSI
06-Oct-14   SSI
06-Oct-14   SSI
06-Oct-14   SSI
06-Oct-14   SSI
03-Oct-14   SSI
07-Oct-14   SCI
02-Oct-14   JSU
02-Oct-14   JSU
30-Sep-14   JSU

sheet 2
SSI    1-Jan-14     10-Jan-16