英文:
AutoFiltering two separate block of data in different rows
问题
第一部分的代码可以保持不变,但是第二部分的代码需要将字段字段(Field)更改为2,以匹配列A中的数据。修改后的代码如下所示:
With ActiveSheet.Range("$A$508:$D$537")
.AutoFilter Field:=2, Criteria1:="<>"
End With
英文:
In a worksheet I'm working on a the moment there are two sections that need to be filtered to show when data is in the cells.
The first section has data in column B and is working fine using the code
With ActiveSheet.Range("$A$48:$D$507")
.AutoFilter Field:=2, Criteria1:="<>"
End With
The next handful of rows have data sitting in column A, but applying the same code as above doesn't seem to include the rows that have data in them. The code I've used is
With ActiveSheet.Range("$A$508:$D$537")
.AutoFilter Field:=1, Criteria1:="<>"
End With
What needs to be changed or added to get the second block of data showing?
答案1
得分: 0
另一位用户评论说,在一个工作表上不能同时使用多个范围的自动筛选(尝试手动操作而不使用VBA - 如果尝试应用第二个筛选条件,它会删除第一个)。
但是,您可以在一个工作表上使用多个表格的自动筛选。首先将您的范围转换为表格,然后像下面这样筛选表格:
ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=2, Criteria1:="<>"
ActiveSheet.ListObjects("Table2").Range.AutoFilter Field:=1, Criteria1:="<>"
英文:
As another user commented, you cannot have autofilters on multiple ranges on one sheet (try doing it manually without VBA - if you try to apply a 2nd filter it will remove the 1st one).
However you can have autofilters on multiple tables on one sheet. Convert your ranges to tables first, then filter the tables like below:
ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=2, Criteria1:="<>"
ActiveSheet.ListObjects("Table2").Range.AutoFilter Field:=1, Criteria1:="<>"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论