+ Reply to Thread
Results 1 to 4 of 4

Animated line chart

Hybrid View

Dudgeon Animated line chart 09-04-2013, 09:57 AM
6StringJazzer Re: Animated line chart 09-04-2013, 11:06 AM
Andy Pope Re: Animated line chart 09-04-2013, 12:07 PM
Dudgeon Re: Animated line chart 09-04-2013, 01:28 PM
  1. #1
    Registered User
    Join Date
    08-27-2011
    Location
    Finland
    MS-Off Ver
    Excel 2003
    Posts
    4

    Animated line chart

    Hello!

    I want an animated line chart. The chart area must stay as it is in the beginning of the animation so only thing that changes in the animation would be the actual line.

    This is what I came up with:

    4iQIP.png

    I have the values in B2:B1001. The chart now takes its data from A2:A1001.
    I wrote a script that copies values from Bx to Ax one by one.

    Sub Macro3()
        Dim i As Long
        For i = 2 To 1001
            Cells(i, 1).Value = Cells(i, 2).Value
            Application.Wait (Now + 0.000002)
        Next i
    End Sub
    It works if the number of rows is small enough and the waiting time is big enough. Otherwise it will crash.

    How do I make this in the right way and animation work smoothly?
    Attached Files Attached Files

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,792

    Re: Animated line chart

    I didn't have any problem running the file you attached.

    Quote Originally Posted by Dudgeon View Post
    It works if the number of rows is small enough and the waiting time is big enough. Otherwise it will crash.
    How many rows is too many?

    How much waiting time is too small? I am not familiar with the implementation of Wait but I suspect that there is some minimum time that will be applied no matter how the small the number gets, just because it takes a certain amount of time for the system to manage the request, and if the number falls below some low threshold it will be treated as 0. Just speculation.

    What exactly do you mean by "crash"? Do you get a VBA runtime error? Does Excel stop responding? If you get any error messages please post the text.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Animated line chart

    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    Sub Macro3()
        Dim i As Long
        Dim chtTemp As Chart
        Dim lngDelay As Long
        
        lngDelay = 10
        If Len(Range("D1")) > 0 Then lngDelay = Range("D1")
        Range("G1").Select
        
        Set chtTemp = ActiveSheet.ChartObjects(1).Chart
        For i = 2 To 1000
            Cells(i, 1).Value = Cells(i, 2).Value
            DoEvents
            Sleep lngDelay
        Next i
    End Sub
    even with very small delay it took a long time to update. and the refresh along with Freeze panes can cause flickering.

    try this variation to speed things up by increase the step size
    
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    Sub Macro3()
        Dim i As Long
        Dim chtTemp As Chart
        Dim lngDelay As Long
        Dim lngStep As Long
        
        lngDelay = 10
        If Len(Range("D1")) > 0 Then lngDelay = Range("D1")
        
        lngStep = 10
        If Len(Range("E1")) > 0 Then lngStep = Range("E1")
        
        Range("G1").Select
        
        Set chtTemp = ActiveSheet.ChartObjects(1).Chart
        For i = 2 To 1000 Step lngStep
            Cells(i, 1).Resize(lngStep, 1).Value = Cells(i, 2).Resize(lngStep, 1).Value
            DoEvents
            Sleep lngDelay
        Next i
        
    End Sub
    Last edited by Andy Pope; 09-04-2013 at 12:10 PM.
    Cheers
    Andy
    www.andypope.info

  4. #4
    Registered User
    Join Date
    08-27-2011
    Location
    Finland
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Animated line chart

    Thanks Andy!

    I guess the biggest problem here was those frozen panels. Now everything works like a charm!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Animated line chart
    By lovethepirk in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-12-2013, 06:01 AM
  2. Animated images on a chart
    By j_Southern in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 01-27-2012, 10:44 AM
  3. Animated images on a chart
    By j_Southern in forum Excel General
    Replies: 0
    Last Post: 01-27-2012, 10:44 AM
  4. Animated XY Chart?
    By Cam in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 07-06-2011, 05:48 AM
  5. Animated Excel chart.....
    By Cam in forum Excel General
    Replies: 8
    Last Post: 03-29-2011, 02:45 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1