Does a named range is dynamically updated on new insertion rows?


The named range is defined in an excel file (used as an template file) that gets loaded at statup, and then I insert rows within the range. It appears to me that the range rowCount doesn't change after insertion. eg.

Range rng = excel.Worksheets.GetRangeByName("dataGroup");

int rowCount = rng.RowCount;

rng.Worksheet.Cells.InsertRows(rng.FirstRow+1, 100);

Debug.Assert(rowCount == rng.RowCount + 100); // this seems to fail.

rng[rng.RowCount + 99].PutValue("test"); // this will throw out of range exception

Any suggestions?


Please try this attached fix.

And there are some errors in your code, I think it should be:

Debug.Assert(rowCount == rng.RowCount - 100);

rng[rng.RowCount + 99, 0].PutValue("test");