I have a dynamic chart that gets updated for hourly data, based on a cell value. That cell is controlled by a scroll button or entering the date manually in another cell. Take a look at the gif below for an insight;
What I want to do is updating the chart using VBA to make it like an animation. Let's have this (pseudo-)code below;
Option Explicit
#If VBA7 And Win64 Then
'64 bit Excel
Public Declare PtrSafe Sub Sleep Lib "kernel32" ( _
ByVal dwMilliseconds As Long)
#Else
'32 bit Excel
Public Declare Sub Sleep Lib "kernel32" ( _
ByVal dwMilliseconds As Long)
#End If
Sub Animate()
On Error GoTo Error ErrorHandler
Dim wsh As Worksheet
Dim i As Integer
Set wsh = ThisWorkbook.Worksheets("AChart")
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
For i = 1 to 3000
Sleep 50
wsh.Range("K4").Value = i
DoEvents
Application.Wait Now() + TimeSerial(0, 0, 1)
Next i
Exit Sub
ErrorHandler:
MsgBox Err.Description & " Procedure Animated Graph"
End Sub
This (particularly DoEvents) does not make the graph update on the screen. I wanted to know if there's a way to implement this.
