vba 运行时错误“1004”:范围类的自动过滤方法失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45190903/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 12:55:53 来源:igfitidea点击:
run-time error '1004': Autofilter method of range class failed
提问by Anna Smith
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
问候安娜·史密斯
回答by Egan Wolf
Problems in your code are:
您的代码中的问题是:
- What @Cyril said in comments with update from @DavidZemens
- @Cyril 在评论中所说的内容来自@DavidZemens 的更新
"Autofilter , Field"
where that ", " isn't needed and the criteria might need to be"=" & Mon
"Autofilter , Field"
不需要“,”的地方,标准可能需要"=" & Mon
- You cannot set manually
ActiveSheet.AutoFilterMode = True
, but it's set automatically when callingActiveSheet.Range("A1:E1").AutoFilter ...
. You can only setActiveSheet.AutoFilterMode = False
to turn the AutoFilter off.
- 不能手动设置
ActiveSheet.AutoFilterMode = True
,但调用时会自动设置ActiveSheet.Range("A1:E1").AutoFilter ...
。您只能设置ActiveSheet.AutoFilterMode = False
关闭自动筛选。