简体   繁体   English

运行时错误“1004”:范围类的自动过滤方法失败

[英]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:您的代码中的问题是:

  1. 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

  1. You cannot set manually 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.

相关问题 运行时错误'1004-Range类的AutoFilter方法失败 - Run-Time error '1004 - AutoFilter method of Range class failed 运行时错误1004 - 范围类的自动过滤方法失败 - Run-time error 1004 - Autofilter Method of Range Class Failed 运行时错误“1004”--范围类的自动过滤方法失败 - Run-time Error '1004'-- AutoFilter Method of Range Class Failed 运行时错误:Range AutoFilter上的'1004' - Run-time error: '1004' on Range AutoFilter 运行时错误'1004:范围类的小计方法失败 - Run-time error '1004: Subtotal method of range class failed 运行时错误'1004:范围 class 的 PasteSpecial 方法失败 - Run-time error '1004: PasteSpecial method of Range class failed 运行时错误'1004':Range类的PasteSpecial方法失败 - Run-time error '1004': PasteSpecial method of Range class failed VBA:为什么自动过滤器在手动过滤器时不起作用? (运行时错误'1004':对象'Range'的方法'AutoFilter'失败) - VBA: Why will Autofilter not work when manual filter does? (Run-time error '1004': Method 'AutoFilter' of object 'Range' failed) 错误信息 Run time error 1004 Autofilter method or range class failed - Error message Run time error 1004 Autofilter method or range class failed 录制的 VBA 宏 - 运行时错误 1004 范围类的自动过滤方法失败 - Recorded VBA macro - run time error 1004 autofilter method of range class failed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM