• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 197
  • Last Modified:

Excel 2013 shape height change display mystery

I'm trying to understand this. I have a shape that I want to animate its height growing. Like this

Sub ShapeHeightAnimation()

    Dim Total As Double

    ActiveSheet.Shapes("Rectangle 1").Height = 0
        
    For i = 1 To 100
        ActiveSheet.Shapes("Rectangle 1").Height = i
        
        'slow down
        For iRow = 1 To 8000
            Total = Total + Sheet2.Cells(iRow, 1).Value / 1000
        Next iRow        
    Next i

End Sub

Open in new window


BUT, the shape does not change height during the For-Next loop, but it updates the display only when the code has finished running. (Note the 'slow down')
I tried Application.ScreenUpdating = True but had no effect.

My simple animation test should work, right?
0
hindersaliva
Asked:
hindersaliva
1 Solution
 
GrahamSkanCommented:
You have to give up some processing time to allow Windows to redraw the shape.You can do that with  the DoEvents statement.
Sub ShapeHeightAnimation()
    Dim i As Integer
    Dim iRow As Integer
    Dim Total As Double

    ActiveSheet.Shapes("Rectangle 1").Height = 0
        
    For i = 1 To 100
        ActiveSheet.Shapes("Rectangle 1").Height = i
        DoEvents
        'slow down
        For iRow = 1 To 8000
            Total = Total + Sheet2.Cells(iRow, 1).Value / 1000
        Next iRow
    Next i

End Sub

Open in new window

0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now