0
I’m doing an Excel Add-In in Visual C# (VSTO)...
I wanted to iterate on the cells of a selection (which may be discontinuous) that are not "Hidden" (hidden). This selection may be large.
So, if you have 4000 lines, in Excel I make the filters (for example cells with ID<=100), and after selecting the lines press the App button. (Let’s imagine selecting A1:A4000, which only has 100 visible lines...).
How do I do this with a foreach
, for example, or with a .Where
(Linq)?
I tried the following code:
Excel.Range selectedRange = null;
foreach (Excel.Range row in myFullRange.Rows)
{
if (!row.Hidden)
selectedRange = Globals.ThisAddIn.Application.Union(selectedRange, row);
}
but this does not work: it seems that selectedRange
can’t be null
.
PS - I’m using Microsoft Interop...