简体   繁体   English

Excel VBA-如何创建(不应用)范围内的过滤器?

[英]Excel VBA - How can I create (not apply) a filter in a range?

I have multiple "tables" in the same sheet, I have a dropdown list (Classes, students, teachers) that I use as a menu so when its changed it "redirects" to the cell where the table is in the same sheet, so if I select Classes it goes to cell A2, if I select students it goes to cell A200 and if I select teachers it goes to cell A400. 我在同一工作表中有多个“表”,我有一个下拉菜单(班级,学生,教师)用作菜单,因此当其更改时,它会“重定向”到该表在同一工作表中的单元格,因此如果选择班级,则转到单元格A2;如果选择学生,则转到单元格A200;如果选择教师,则转到单元格A400。 Since I can create only one filter per sheet, how can I create a filter on the table that has been selected, so if I select Students, a filter is created on the range A2:P350. 由于每张纸只能创建一个过滤器,因此如何在已选择的表上创建过滤器,因此,如果选择“学生”,则会在A2:P350范围内创建一个过滤器。

This is so when the user selects an option, he doesn't have to manually create a filter on the range but it is created automatically. 这样,当用户选择一个选项时,他不必手动在范围上创建过滤器,而是自动创建的。

I tried Hoja1.Range("A2:P350").AutoFilter, but it doesn't create the filter. 我尝试了Hoja1.Range(“ A2:P350”)。AutoFilter,但它没有创建过滤器。

This will filter the second column of the range and select all the values equal to "abc" ? 这将过滤范围的第二列,并选择所有等于"abc"的值?

Hoja1.Range("A2:P350").AutoFilter Field:=2, Criteria1:="abc"

You can record a macro while you manually apply the filter to see what the macro recorder does, then create your own macro using the recorded one as inspiration. 您可以在手动应用过滤器时记录宏,以查看宏记录器的功能,然后使用记录的宏作为灵感来创建自己的宏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM