ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VSTO: insert one row into a 1-row range (https://www.excelbanter.com/excel-programming/365162-vsto-insert-one-row-into-1-row-range.html)

jj_online

VSTO: insert one row into a 1-row range
 
I have a programming written in C#, trying to insert a new row into a
range. If the range has two rows or more than two rows, all work just
fine. However, if the range only has one row, the insert doesn't work
quite right. The insert seems working (visually the worksheet has one
more row), but the range is not updated. The code looks like the
following:

NamedRange nr = Controls.AddNamedRange("A1", Type.Missing);
Range r = nr.Cells[1,1].EntireRow;
r.Insert(XlInsertShiftDirection.xlShiftDown, Type.Missing);

After above code, I would expect that the namedrange nr has two rows.
But it still has one row even a new row is actually insert into
worksheet.

However, if the namedrange has two rows or more, after executing above
codes, nr.Rows.Count will be incremented.

What can be wrong in my code? Does it mean NamedRange doesn't work for
1 row range?

Thanks for reading and help!

JJ



All times are GMT +1. The time now is 01:34 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com