View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
jj_online jj_online is offline
external usenet poster
 
Posts: 1
Default 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