View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
JDias JDias is offline
external usenet poster
 
Posts: 2
Default Excel VSTO: Selecting range according to properties

I am creating an Excel VSTO Add-In in C# with Visual Studio, and I'm using the library Microsoft.Office.Microsoft.Office.Interop.Excel .
This app gets a range (e.g. 4000 contiguous rows) which may contain thousands of hidden rows (by an usual Excel filter). So, I start using:

// Gets the selected range
Excel.Worksheet activeWorksheet = Globals.ThisAddIn.Application.ActiveSheet;
Excel.Range activeRange = Globals.ThisAddIn.Application.Selection.Cells;
Excel.Range expandedRange = activeRange.EntireRow; // selects entire rows

and then I would like to create a multiselection only with the not-hidden rows... or if you prefer create a multiselection according to the active filter.

I tried:

Excel.Range selectedRange = null;

foreach (Excel.Range row in expandedRange.Rows)
{
if (!row.Hidden)
selectedRange = Globals.ThisAddIn.Application.Union(selectedRange, row);
}

but this gave a runtime error...

Could anyone help me?