Question: I've been working in a c# project and what I'm trying to accomplish is counting the visible rows of a filtered range in C#.

First, I create a range that I'm going to filter.

```
Range usedRange = sheet.Range[sheet.Cells[7, 1], sheet.UsedRange.SpecialCells(XlCellType.xlCellTypeLastCell)];

```

Then, I apply 2 filters:

```
  usedRange.AutoFilter(20, "<>RAW", XlAutoFilterOperator.xlFilterValues, "<>AV", true);
  usedRange.AutoFilter(2, "ARG", XlAutoFilterOperator.xlFilterValues, Type.Missing, true);

```

And last, I create another range, using the "XlCellType.xlCellTypeVisible" and try to count the rows, **but the count returns 1**

```
  argFiltered = usedRange.SpecialCells(XlCellType.xlCellTypeVisible);
  Console.WriteLine("Number of rows: "+ argFiltered.Rows.Count) // the count returns 1.

```

If I loop through the Range I Can get the count. But with a big amount of data this can slow the process a lot:

```
//this is not effective
foreach (Range area in argFiltered.Areas) {
    foreach (Range areaRow in area) {
      count++;
    }
  }

```

**My question is: is there any way to get the number of the visible filtered rows "directly"?**

Thank you all!

Note:
If I select the range, it selects the exact number of rows that should be displayed in the count!.

```
argFiltered.Select();

```

Answer: 
Not ideal but this will be somewhat better:

```
foreach (Range area in argFiltered.Areas) {
    count += area.Rows.Count;
}

```
Can you afford to put a formula in some unused cell that counts the rows? If you use the [Subtotal](https://exceljet.net/formula/count-visible-rows-in-a-filtered-list) function with code 3 it won't count the rows hidden by a filter. Put a formula in a cell and read its value, e.g.

```
sheet.Cells[1, 255].Formula = "=subtotal(3, A1:A16383)"; //Count all rows that have a non-blank column A and aren't hidden
var count = sheet.Cells[1, 255].Value;
sheet.Cells[1, 255].ClearContents();

```