Solved

Excel 2013 shape height change display mystery

Posted on 2014-12-13
1
186 Views
Last Modified: 2014-12-13
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
Comment
Question by:hindersaliva
1 Comment
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 40498175
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question