ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Reading data from a filtered list (https://www.excelbanter.com/excel-programming/328139-reading-data-filtered-list.html)

Lucas Soler

Reading data from a filtered list
 
I need some brain surgery, or the answer to the following:
I'd like to read two columns of data displayed by a filter into an array.
Assume that the data is already filtered by column A when the file is opened.

Cheers.



Tom Ogilvy

Reading data from a filtered list
 
Dim vArr()
Dim maxnum as Long, i as Long
Dim cell as Range

maxnum = Activesheet.Autofilter.Range _
.columns(1).specialCells(xlVisible).Count - 1
if maxnum = 0 the exit sub
redim varr(1 to maxnum, 1 to 2)
i = 1
for each cell in ActiveSheet.Autofilter.Range.columns(1).Cells
if cell.Row < ActiveSheet.Autofilter.Range.row then
if cell.EntireRow.Hidden = False then
varr(i,1) = cell.value
varr(i,2) = cell.offset(0,1).Value
i = i + 1
end if
end if
next
Redim
You could also use specialcells to get just the visible rows. this might be
faster.

--
Regards,
Tom Ogilvy


"Lucas Soler" wrote in message
...
I need some brain surgery, or the answer to the following:
I'd like to read two columns of data displayed by a filter into an array.
Assume that the data is already filtered by column A when the file is

opened.

Cheers.






All times are GMT +1. The time now is 11:41 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com