[英]Select a number of columns in an excel table for advanced filter
I have created raw data within a table, I use an advanced filter by VBA but when I run the codes, the table disappeared so I try to write a code to select many columns but I received an error every time I tried我在表格中创建了原始数据,我使用了 VBA 的高级过滤器,但是当我运行代码时,表格消失了,所以我尝试将代码写入 select 很多列,但每次尝试时都会收到错误
The code编码
'Assuming the name of the table is "RawData"
LastTransRow = Sheet9.ListObjects("RawData").DataBodyRange(19999, 1).End(xlUp).Row 'Last Transaction Row
Sheet9.ListObjects("RawData").DataBodyRange("G1:A" & LastTransRow).AdvancedFilter xlFilterCopy, CriteriaRange:=Sheet11.Range("A2:B3"), CopyToRange:=Sheet11.Range("K2:E19999"), Unique:=True
I added references to the Workbook that contains the code (ThisWorkbook) in order to ensure that operations are performed on its child sheets.我添加了对包含代码 (ThisWorkbook) 的工作簿的引用,以确保在其子工作表上执行操作。 Reset some arguments (eg: "G1:A" >>> "A1:G", "K2:E19999" >>> "E2:K19999").
重置一些 arguments(例如:“G1:A”>>>“A1:G”,“K2:E19999”>>>“E2:K19999”)。 Worked on my machine.
在我的机器上工作。 Give it a try.
试试看。
Sub AdvFilterTest()
Dim LastTransRow As Long
'Assuming the name of the table is "RawData"
With ThisWorkbook.Sheets("Sheet9")
.Activate
LastTransRow = .ListObjects("RawData").DataBodyRange(19999, 1).End(xlUp).Row 'Last Transaction Row
.ListObjects("RawData").DataBodyRange.Range("A1:G" & LastTransRow).AdvancedFilter xlFilterCopy, CriteriaRange:=ThisWorkbook.Sheets("Sheet11").Range("A2:B3"), CopyToRange:=ThisWorkbook.Sheets("Sheet11").Range("E2:K19999"), Unique:=True
End With
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.