简体   繁体   English

Excel VBA - 过滤动态范围内的行

[英]Excel VBA - filter rows within dynamic range

On Excel spreadsheet I want to filter out rows which have TRUE in column J. Running line below works, but only for that specific range - A5:J38:在 Excel 电子表格中,我想过滤掉 J 列中为 TRUE 的行。下面的运行行有效,但仅适用于该特定范围 - A5:J38:

ActiveSheet.Range("$A$5:$J$38").AutoFilter Field:=10, Criteria1:="FALSE"

Need for the range to adjust automatically to include rows which have a result in formula displayed in column J (it's either TRUE or FALSE).需要自动调整范围以包括在列 J 中显示公式的行(它是 TRUE 或 FALSE)。 Code below gives "Run-time error '1004': Application-defined or object-defined error"下面的代码给出了“运行时错误‘1004’:应用程序定义或对象定义的错误”

ActiveSheet.Range(Rows.Count, 10).End(xlUp).AutoFilter Field:=10, Criteria1:="FALSE"

I believe you just need to make a small edit:我相信你只需要做一个小的编辑:

With ActiveSheet
    lastRow = .Cells(.Rows.Count, 10).End(xlUp).Row
    .Range("A5:J" & lastRow).AutoFilter Field:=10, Criteria1:="FALSE"
End With

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

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