[英]run-time error '1004': Autofilter method of range class failed
I have used a small code in vba which gives me this error::我在 vba 中使用了一个小代码,它给了我这个错误::
Dim today As Date
Dim Mon As Integer
today = VBA.Date()
Mon = Month(today)
Sheets("Birthday List").Activate
ActiveSheet.AutoFilterMode = False
ActiveSheet.Range("A1:E1").AutoFilter , Field:=3, Criteria1:=Mon, Operator:=xlFilterValues
ActiveSheet.AutoFilterMode = True
Could you please help me how to correct it你能帮我改正吗
regards Anna Smith问候安娜·史密斯
Problems in your code are:您的代码中的问题是:
"Autofilter , Field"
where that ", " isn't needed and the criteria might need to be"=" & Mon
"Autofilter , Field"
不需要 ", " 并且标准可能需要是"=" & Mon
ActiveSheet.AutoFilterMode = True
, but it's set automatically when calling ActiveSheet.Range("A1:E1").AutoFilter ...
.ActiveSheet.AutoFilterMode = True
,但它会在调用ActiveSheet.Range("A1:E1").AutoFilter ...
时自动设置。 You can only set ActiveSheet.AutoFilterMode = False
to turn the AutoFilter off.ActiveSheet.AutoFilterMode = False
来关闭自动筛选。I'm not sure if this is already resolved (it's years old) but I had a similar error '1004': Autofilter method of range class failed today and it turned out that the data I was supposed to be filtering was in a table and that borked it.我不确定这是否已经解决(已经有几年了)但我遇到了类似的错误“1004”:今天范围类的自动过滤方法失败,结果我应该过滤的数据在表中,并且这让它厌烦了。 (The user who sends the report changed how they send it)
(发送报告的用户改变了他们的发送方式)
De-tabling the data (Convert Table to Range) resolved my issue.删除数据表(将表转换为范围)解决了我的问题。 Maybe this will help someone else.
也许这会帮助别人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.