Excel VBA-过滤动态范围内的行 [英] Excel VBA - filter rows within dynamic range

查看:67
本文介绍了Excel VBA-过滤动态范围内的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Excel电子表格上,我想过滤出J列中为TRUE的行.下面的运行行有效,但仅适用于特定范围-A5:J38:

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:

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

需要范围自动调整以包括在J列中显示公式中结果为结果的行(为TRUE或FALSE).下面的代码给出了运行时错误'1004':应用程序定义的错误或对象定义的错误"

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). Code below gives "Run-time error '1004': Application-defined or object-defined error"

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

这篇关于Excel VBA-过滤动态范围内的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆