How can I get the Range of filtered rows using Excel Interop?

calendar_today Asked Dec 16, 2009
thumb_up 8 upvotes
history Updated April 16, 2026

Question posted 2009 · +5 upvotes

I’m using Excel Interop assemblies for my project, if I want to use auto filter with then thats possible using

sheet.UsedRange.AutoFilter(1,SheetNames[1],Microsoft.Office.Interop.Excel.XlAutoFilterOperator.xlAnd,oMissing,false)

but how can I get the filtered rows ??

can anyone have idea??

Accepted answer +8 upvotes

Once you filtered the range, you can access the cells that pass the filter criteria by making use of the Range.SpecialCells method, passing in a valued of ‘Excel.XlCellType.xlCellTypeVisible’ in order to get the visible cells.

Based on your example code, above, accessing the visible cells should look something like this:

Excel.Range visibleCells = sheet.UsedRange.SpecialCells(
                               Excel.XlCellType.xlCellTypeVisible, 
                               Type.Missing)

From there you can either access each cell in the visible range, via the ‘Range.Cells’ collection, or access each row, by first accessing the areas via the ‘Range.Areas’ collection and then iterating each row within the ‘Rows’ collection for each area. For example:

foreach (Excel.Range area in visibleCells.Areas)
{
    foreach (Excel.Range row in area.Rows)
    {
        // Process each un-filtered, visible row here.
    }
}

Hope this helps!

Mike

2 code variants in this answer

  • Variant 1 — 3 lines, starts with Excel.Range visibleCells = sheet.UsedRange.SpecialCells(
  • Variant 2 — 7 lines, starts with foreach (Excel.Range area in visibleCells.Areas)

Excel VBA objects referenced (5)

Top excel Q&A (6)

+8 upvotes ranks this answer #106 out of 167 excel solutions on this site .