charts and shapes does not move when row inserted in excel in c# programmatically


February 2019


1.7k time


When I insert a row in Excel charts and other shapes does not move with their cells.
Let's say I have a chart at A5:D:10, then i insert a row below 2nd row, so now chart should be at A6:D:11, but the chart stays there and hides the 5th row.

I design a template containing a chart and a shape, then at runtime I am supplying data to the chart and changing a few properties of the shapes. Now my chart contains some data in its first 5 rows and I insert a row after the 2nd row then everything should go one row down, but this is not happening.

At design time I have checked if the chart's property to move and size with cells is set to true. Yet this is not happening at runtime programmatically. Although at design time inserting rows have no issues.

Please help me to solve my problem

3 answers


I had the same problem and managed to fix it by unlocking the chart(s).


i solved it with workaround, incase somebody comes looking -
chart and shapes are still not moving, but now i am assigning TopLeftCell property of chart and shape at runtime and forcing them to move, although now i have overhead of keeping its location.


I had this problem, and setting any of the graph's properties made no difference. I traced my problem, it was due to having multiple sheets in my workbook. I was inserting cells in a number of sheets but only ever having the first sheet active.

If I added currentsheet.Activate(); before I inserted cells the graph moved as you'd had expected it to.