我试图将3个过滤器放在3列中,其中一个是资源名称,第二个是状态,第三个是日期。对于每个资源名称,我需要找到在当月之前3个月创建的故障单,状态列应该有2个值,"新"和"打开"。我写了下面的代码,但它给了我0结果作为回报。如果我要将第3个过滤条件更改为">" &安培; premier_jour_3,它显示了3个月之前的结果以及在premier_jour_3之后的最新结果。如果在premier_jour_3 = 01/11/2017,它会显示日期和#34; 07/09/2017 17:59:00"和#34; 31/07/2017 10:35:00"
premier_jour_3 = DateSerial(Year(Date), Month(Date) - 3, 1)
With Worksheets("general_report")
.AutoFilterMode = False
.Range("A1:R100000").Select
Selection.AutoFilter
Worksheets("general_report").Range("C1").AutoFilter Field:=3, Criteria1:="ResourceName", Operator:=xlAnd
Worksheets("general_report").Range("F1").AutoFilter Field:=6, Criteria1:=Array("Opened", "New"), Operator:=xlFilterValues
Worksheets("general_report").Range("H1").AutoFilter Field:=8, Criteria1:="<" & premier_jour_3, Operator:=xlAnd
row_cnt_nt_upd = Evaluate("=subtotal(3,A:A)") - 1
End With
答案 0 :(得分:0)
.AutoFilter喜欢它在字符串中的标准。对于日期,此字符串必须采用EN-US格式mm/dd/yyyy
或MDY,无论区域设置如何。
premier_jour_3 = DateSerial(Year(Date), Month(Date) - 3, 1)
With Worksheets("general_report")
if .AutoFilterMode then .AutoFilterMode = False
with .Range("A1:R100000")
.AutoFilter Field:=3, Criteria1:="ResourceName"
.AutoFilter Field:=6, Criteria1:=Array("Opened", "New"), Operator:=xlFilterValues
.AutoFilter Field:=8, Criteria1:=format(premier_jour_3, "\<mm/dd/yyyy")
row_cnt_nt_upd = Evaluate("=subtotal(3,A:A)") - 1
end with
End With