In a large project I add a large number of shapes at different positions in a Worksheet. Furthermore, I insert a number of rows.
I want the shapes to move with the inserted rows. However, they only do so with Application.ScreenUpdating = True
. As soon as ScreenUpdating is set False
, the shapes stop moving. This of course messes up the results completely.
I cannot reproduce the problem. In this minimal example, the inserted shapes move as expected with the inserted row, although I use Application.ScreenUpdating = False
. In my larger program the basically identical procedure fails without ScreenUdating.
Sub ShapeTest()
Dim ActiveShape As Shape
Dim ShapeCell As Range
Application.ScreenUpdating = False
Set ShapeCell = ActiveSheet.Range("A1")
Set ActiveShape = ActiveSheet.Shapes.AddShape(msoShapeRectangle, ShapeCell.Left, ShapeCell.Top, ShapeCell.Width, ShapeCell.Height)
ActiveSheet.Rows(1).Insert shift:=xlShiftDown
Application.ScreenUpdating = True
End Sub
Update
I have tried DoEvents
before and after inserting the row, but it didn't change anything. Currently I am using this workaround:
Application.ScreenUpdating = True
Worksheets("Gantt").Rows(ThisRowGTT).Insert shift:=xlShiftDown
Application.ScreenUpdating = False
This slows down the execution alot - almost as if I would use ScreenUpdating for the entire program.