Can't refresh a chart in Excel VBA (Excel 2016)

后端 未结 2 1954
遇见更好的自我
遇见更好的自我 2021-01-24 07:30

My son (15 y) is studying pendulum at school, physics lessons. I am trying to help him with a simulated pendulum in Excel, using 2 points chart, one fix (where the \"cord\" of

2条回答
  •  囚心锁ツ
    2021-01-24 07:56

    It's 2020 and am running Excel 2016 for MAC. I put this subroutine in my code (combined various items I found on the web) and got the chart to update each time the sub is called (be sure to define a cell in your worksheet as "stepper" so the counter data can be stored and updated). My chart was auto-named "chart 8" by excel:

    Sub ChartAnimation3()
      Dim i As Double
      For i = 0 To 1000 Step 500
        ActiveSheet.Range("Stepper") = i
        DoEvents
        DoEvents
      Next
    
    ActiveSheet.ChartObjects("Chart 8").Chart.Refresh
    ActiveSheet.ChartObjects("Chart 8").Activate
    ActiveChart.Refresh
    DoEvents
    
    End Sub
    

    There might be some items not needed in this code, but I'm a novice, and it worked, so I am satisfied.

提交回复
热议问题