Charts Do Not Automatically Update When Data Changes

后端 未结 9 2820
庸人自扰
庸人自扰 2021-02-19 18:52

Hopefully this is an easy one. I have a series of charts in MS Excel that point to data on the same worksheet. The data on the worksheet is calculated using a VBA function. W

9条回答
  •  借酒劲吻你
    2021-02-19 19:47

    This solution worked for me. For the offending worksheet add:

    Private Sub Worksheet_Activate()
      Dim rngSelection          As Range
      Dim objChartObject        As ChartObject
      Dim objChart              As Chart
      Dim objSeriesCollection   As SeriesCollection
      Dim objSeries             As Series
      Dim strFormula            As String
    
      Set rngSelection = Selection
    
      For Each objChartObject In Me.ChartObjects
        Set objChart = objChartObject.Chart
        Set objSeriesCollection = objChart.SeriesCollection
        For Each objSeries In objSeriesCollection
          strFormula = objSeries.Formula
    
          objSeries.Delete
    
          Set objSeries = objSeriesCollection.NewSeries
    
          objSeries.Formula = strFormula
        Next objSeries
      Next objChartObject
    
      rngSelection.Select
    End Sub
    

提交回复
热议问题