下面是我想出的代码,但是问题出在第 3 行,其中过滤后的数据不一定从第 2 行开始。如果满足条件的第一个数据点位于第 150 行,那么它将返回错误:
Total_Rows_Compiled = Worksheets("Compiled").Range("A" & Rows.Count).End(xlUp).Row
Worksheets("Compiled").Range("$A$1:$G$52818").AutoFilter Field:=1, Criteria1:=Worksheets("Sheet1").Cells(l, 1)
Worksheets("Compiled").Range("A2:G" & Total_Rows_Compiled).SpecialCells(xlCellTypeVisible).Select
最佳答案
您的代码似乎没有任何重大错误。考虑到这一点,以下是我发现相当无错误的方法组合。
with Worksheets("Compiled")
.activate
if .autofiltermode then .autofiltermode = false
Total_Rows_Compiled = .Range("A" & .Rows.Count).End(xlUp).Row
with .range("A1:G" & Total_Rows_Compiled)
.AutoFilter Field:=1, Criteria1:=Worksheets("Sheet1").Cells(l, 1)
with .resize(.rows.count-1, .columns.count).offset(1, 0)
if cbool(application.subtotal(103, .cells)) then
.SpecialCells(xlCellTypeVisible).Select
end if
end with
end with
end with
关于vba - 如何使用Excel VBA选择过滤后的数据而不包含列名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48939559/