简体   繁体   中英

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?

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.

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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