我的问题是关于VBA countifs()正在评估一列中的字母数据和另一列中的数字数据。我已经在本表的另一部分使用了多个标准countifs()。那个公式看起来像这样:
Filedresult = WorksheetFunction.CountIfs(range("n:n"), "TT", range("P:P"), "Filed")
MsgBox Filedresult
以下是我需要帮助的过滤器代码。我需要Countifs()过滤器来计算单元格的数量:
在W = 2017列中的StartYear和在Start Week& EndWeek = 1& 4 OR具有WeekValue = 1,2,3和4
Dim StartYear As Integer
Dim StartWeek As Integer
Dim EndWeek As Integer
'Setting Start Year, Start Week, and End Weeks
StartYear = WBsheetTwo.range("g5")
MsgBox StartYear
'THIS VALUE CURRENTLY ='s 2017
StartWeek = WBsheetTwo.range("g6")
MsgBox StartWeek
'THIS VALUE CURRENTLY ='s 1
EndWeek = WBsheetTwo.range("g7")
MsgBox EndWeek
'THIS VALUE CURRENTLY ='s 4
这是我迄今为止尝试构建的过滤器,它基于我之前在上面构建的countifs()的结构。
我已经根据读者的要求重新编写了这篇文章,试图让我的问题更加清晰。如果还有什么我可以澄清的,请告诉我!论坛还是新手!谢谢你的帮助
****************************************FILTER*************************
'WEEK FILTER for # of TT Values
If WBsheetTwo.range("h6").Value = "YES" Then
MsgBox "Week Filter Is ON"
WBsheetOne.Activate
TTresultWFilter = WorksheetFunction.CountIfs _
(range("n:n"), "TT", _
range("w:w"), "&StartYear&", _
range("x:x"), "1", _
range("x:x"), "2", _
range("x:x"), "3", _
range("x:x"), "4")
MsgBox TTresultWFilter
Else
MsgBox "Week Filter if OFF"
'Pasting Origional TT Filter W/O Weeks Filter
WBsheetTwo.Activate
range("f12").Value = TTresult
****************************************FILTER*************************
答案 0 :(得分:0)
更改
TTresultWFilter = WorksheetFunction.CountIfs _
(range("n:n"), "TT", _
range("w:w"), " & StartYear & ", _
range("x:x"), "1", _
range("x:x"), "2", _
range("x:x"), "3", _
range("x:x"), "4")
要
TTresultWFilter = WorksheetFunction.CountIfs _
(range("n:n"), "TT", _
range("w:w"), " & StartYear & ", _
range("x:x"), ">=" & StartWeek & ", _
range("x:x"), "<=" & EndWeek & ")"