应用自动过滤器后,Excel VBA 从可见单元格中获取范围值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26645914/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Excel VBA get a range value from visible cells after applying autofilter
提问by De De De De
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 的范围作为函数返回。
回答by barryleajo
Set the .SpecialCells(xlCellTypeVisible)
to a Range, then use Cells(row, column)
on this range to pick out the value that you require. If you are using headers in the result then you may also have to use Offset(1,0)
to address your data. So where 'MySheet' has been defined as a Worksheet object, smething like:
将 设置.SpecialCells(xlCellTypeVisible)
为范围,然后Cells(row, column)
在此范围内使用以挑选出您需要的值。如果您在结果中使用标头,那么您可能还必须使用标头来Offset(1,0)
寻址您的数据。因此,其中 'MySheet' 已被定义为 Worksheet 对象,类似于:
Set rsltRng = MySheet.Autofilter.Range.SpecialCells(xlCellTypeVisible)
msgbox rsltRng.cells(2,2)