gpt4 book ai didi

vba - Excel VBA查找过滤范围的最后一行

转载 作者:行者123 更新时间:2023-12-04 20:59:56 35 4
gpt4 key购买 nike

我正在尝试在工作表上查找过滤范围的行数。 LstRow2 是我要查找的变量。使用此代码,我得到未过滤的行数。

   CSht.Range(CSht.Cells(1, 1), CSht.Cells(LstRow1, LstCol1)).AutoFilter Field:=2, Criteria1:="RA"
With CSht
LstRow2 = .UsedRange.SpecialCells(xlCellTypeLastCell).Row
End With

Here is the data that I am filtering

最佳答案

您只需要使用可见单元格,因为它已被过滤。

尝试这个:

 With CSht

'load filter cells into Range object
Dim rngFilter as Range
Set rngFilter = Intersect(.UsedRange,.UsedRange.Offset(1)).SpecialCells(xlCellTypeVisible)

'find the max number of elements split by $ in the range address
'needs to be dynamic because of areas
Dim lUpper as Long
lUpper = UBound(Split(rngFilter.Address,"$"))

'the last element will be the last row in the filtered range
'the last number in the rngFilter.Address
Dim LstRow2 as Long
LstRow2 = Split(rngFilter.Address,"$")(lUpper)

End With

关于vba - Excel VBA查找过滤范围的最后一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38268291/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com