views:

334

answers:

2

OK, so I have set AutoFilter property for the whole of the active worksheet (UsedRange.AutoFilter Field:=1, Criteria1:= [blah blah])

Once the filter is applied, how do I programmatically select the range if rows and columns that are the result of the filter.

I checked UsedRange, but that gives the whole (unfiltered) range. Any ideas?

+1  A: 

Got it.

Set rng = Worksheets("Sheet1").Range("A1").CurrentRegion.SpecialCells(xlVisible)
LVS
rng.Rows.Count shows the number if rows in the filtered range. but rng.Cells property seems to reference the whole range in the sheet
LVS
A: 

The same does not appear to be true for C#. I have the following:

Excel.Range filteredRange = ((Excel.Worksheet)this.Application.ActiveSheet).get_Range("A1", System.Type.Missing).CurrentRegion.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeVisible, Type.Missing);

filteredRange.Rows.Count always returns 1.

Does anyone know how to get the filtered range? Even better, can someone tell be how to get the selected range in and already filtered range?

Apothas