简体   繁体   English

应用自动筛选后,Excel VBA从可见单元格获取范围值

[英]Excel VBA get a range value from visible cells after applying autofilter

Is it not possible to do something simple like this to get the range value of B2? 这样不可能做简单的事情来获取B2的范围值吗?

crdata.Range("B2").SpecialCells(xlCellTypeVisible).Value

I have applied the autofilter to filter out with the given criteria and trying to return the range of B2 as a function. 我已应用自动过滤器以给定条件过滤掉并尝试将B2的范围作为函数返回。

Set the .SpecialCells(xlCellTypeVisible) to a Range, then use Cells(row, column) on this range to pick out the value that you require. .SpecialCells(xlCellTypeVisible)为一个范围,然后在此范围上使用Cells(row, column)以选择所需的值。 If you are using headers in the result then you may also have to use Offset(1,0) to address your data. 如果在结果中使用标题,则可能还必须使用Offset(1,0)来寻址数据。 So where 'MySheet' has been defined as a Worksheet object, smething like: 因此,在将“ MySheet”定义为工作表对象的地方,类似于:

Set rsltRng = MySheet.Autofilter.Range.SpecialCells(xlCellTypeVisible)
msgbox rsltRng.cells(2,2)

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

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