+ Reply to Thread
Results 1 to 10 of 10

Animated line chart

Hybrid View

  1. #1
    Registered User
    Join Date
    04-12-2006
    Posts
    27

    Animated line chart

    I would like to use the data in the upload to create an animated line chart.

    Is there a simple way to do this? Thanks for any help....

    Here is a link to show what I am looking for:
    http://www.youtube.com/watch?v=yph8TRldW6k
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Animated line chart

    Try this macro.

    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
        
    Sub Animated_Chart()
        Dim i As Long, Lr As Long
        
        Range("H1").Select
        Lr = Range("B" & Rows.Count).End(xlUp).Row
        
        
        With ActiveSheet.ChartObjects(1).Chart
            .Axes(xlValue).MaximumScale = Int(Application.Max(Range("B2:F" & Lr))) + 1
            For i = 2 To Lr
                .SeriesCollection(1).Values = Range("B" & i).Resize(, 5)
                .ChartTitle.Characters.Text = Format(Range("A" & i), "mmmm yyyy")
                DoEvents
                Sleep 300   'Animation speed: milliseconds/frame
            Next i
        End With
        
    End Sub
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    04-12-2006
    Posts
    27

    Re: Animated line chart

    Thanks for the help....I get this error about 64 bit systems

    https://dl.dropboxusercontent.com/u/90210377/error.JPG
    Last edited by lovethepirk; 08-08-2013 at 04:50 PM.

  4. #4
    Registered User
    Join Date
    04-12-2006
    Posts
    27

    Re: Animated line chart

    I couldn't get the VBA to work so what I have done is attached. I added a 'scrollbar'

    I would like to be able to click a 'play button' to run through the entire scroll bar

    Is there a way to do this instead of clicking the scroll bar 237 times.

    Thanks.
    Attached Files Attached Files

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Animated line chart

    Try this. The #IF #Else #Endif statement goes at the very top of the code module in the module's Declarations section.

    #If VBA7 And Win64 Then
        ' 64 bit Excel
        Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongLong)
    #Else
        ' 32 bit Excel
        Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    #End If
        
    Sub Animated_Chart()
        Dim i As Long, Lr As Long
        
        Range("H1").Select
        Lr = Range("B" & Rows.Count).End(xlUp).Row
        
        With ActiveSheet.ChartObjects(1).Chart
            .Axes(xlValue).MaximumScale = Int(Application.Max(Range("B2:F" & Lr))) + 1
            For i = 2 To Lr
                .SeriesCollection(1).Values = Range("B" & i).Resize(, 5)
                .ChartTitle.Characters.Text = Format(Range("A" & i), "mmmm yyyy")
                DoEvents
                Sleep 300   'Animation speed: milliseconds/frame
            Next i
        End With
        
    End Sub

  6. #6
    Registered User
    Join Date
    04-12-2006
    Posts
    27

    Re: Animated line chart

    Thanks so much.

    Attached is the result so far, check it out.

    Is there anyway to have a button to stop the macro?
    Attached Files Attached Files

  7. #7
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Animated line chart

    Not sure about how to make a stop animation button. There's probably a clever way to make it happen though.

    You can hit the space bar or any character key to stop the code. Note: what you type goes into cell H1 as it's the active cell.

  8. #8
    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 m_blnStopAnimation As Boolean
    Sub Animated_Chart()
        Dim i As Long, Lr As Long
        
        If m_blnStopAnimation Then
            ActiveSheet.Shapes(Application.Caller).TextFrame.Characters.Text = "Stop Animation"
            m_blnStopAnimation = False
        Else
            ActiveSheet.Shapes(Application.Caller).TextFrame.Characters.Text = "Animate"
            m_blnStopAnimation = True
            Exit Sub
        End If
        
        Range("H1").Select
        Lr = Range("B" & Rows.Count).End(xlUp).Row
        
        With ActiveSheet.ChartObjects(1).Chart
            .Axes(xlValue).MaximumScale = Int(Application.Max(Range("B2:F" & Lr))) + 1
            For i = 2 To Lr
                .SeriesCollection(1).Values = Range("B" & i).Resize(, 5)
                .ChartTitle.Characters.Text = Format(Range("A" & i), "mmmm yyyy")
                DoEvents
                Sleep 300   'Animation speed: milliseconds/frame
                If m_blnStopAnimation Then Exit For
    
            Next i
        End With
        
    End Sub
    Cheers
    Andy
    www.andypope.info

  9. #9
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Animated line chart

    @Andy Pope
    That toggles the button caption, but the button isn't click-able while the code is running. So it doesn't stop the code. What am I missing?

  10. #10
    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

    Looks like it needed the button pressed twice in order to get it going.

    I've changed the logic and variable name and now it should anitmate on first press. Note I've increased the speed of anitmation.

    #If VBA7 And Win64 Then
        ' 64 bit Excel
        Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongLong)
    #Else
        ' 32 bit Excel
        Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    #End If
        
    Private m_blnAnimation As Boolean
    Sub Animated_Chart()
        Dim i As Long, Lr As Long
        
        If Not m_blnAnimation Then
            ActiveSheet.Shapes(Application.Caller).TextFrame.Characters.Text = "Stop Animation"
            m_blnAnimation = True
        Else
            ActiveSheet.Shapes(Application.Caller).TextFrame.Characters.Text = "Animate"
            m_blnAnimation = False
            Exit Sub
        End If
        
        Range("H1").Select
        Lr = Range("B" & Rows.Count).End(xlUp).Row
        
        With ActiveSheet.ChartObjects(1).Chart
            .Axes(xlValue).MaximumScale = Int(Application.Max(Range("B2:F" & Lr))) + 1
            For i = 2 To Lr
                .SeriesCollection(1).Values = Range("B" & i).Resize(, 5)
                .ChartTitle.Characters.Text = Format(Range("A" & i), "mmmm yyyy")
                DoEvents
                Sleep 100   'Animation speed: milliseconds/frame
                If Not m_blnAnimation Then Exit For
    
            Next i
        End With
        
    End Sub
    Attached Files Attached Files

+ 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 images on a chart
    By j_Southern in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 01-27-2012, 10:44 AM
  2. Animated images on a chart
    By j_Southern in forum Excel General
    Replies: 0
    Last Post: 01-27-2012, 10:44 AM
  3. Animated XY Chart?
    By Cam in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 07-06-2011, 05:48 AM
  4. Animated Excel chart.....
    By Cam in forum Excel General
    Replies: 8
    Last Post: 03-29-2011, 02:45 PM
  5. Chart Animated Sine Wave
    By TEAM in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 08-05-2005, 05:35 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