Villalobos
Active Member
Hello,
I would like to ask some help from you regarding the chart updating.
I use this code to create chart about the data source:
At the first run the code is working fine, just if I add new data to the source then the code add new series to chart (and change the colors also)... I do not why...
By the way if I run again the code (if data source not changed) the code give back the expected chart result.
The target would be that if the data source has been changed then (after the code run) the chart changing as well (without any bug).
Do you have some idea how could be avoid this kind of problem?
Thanks in advance the reply!
I would like to ask some help from you regarding the chart updating.
I use this code to create chart about the data source:
Code:
Sub WeeklyChart()
Dim SourceSheet1 As Worksheet
Dim SourceLastrow1 As Long
Dim cht2 As Chart
Set SourceSheet1 = Worksheets("Evaluation")
With SourceSheet1
SourceLastrow1 = .Cells(.Rows.Count, "T").End(xlUp).Row
End With
Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SeriesCollection.NewSeries
ActiveChart.HasLegend = False
ActiveChart.HasTitle = False
ActiveChart.SeriesCollection(1).XValues = "=Evaluation!R9C21:R" & SourceLastrow1 & "C21"
ActiveChart.SeriesCollection(1).Values = "=Evaluation!R9C23:R" & SourceLastrow1 & "C23"
ActiveChart.SeriesCollection(1).Interior.Color = RGB(204, 204, 255)
ActiveChart.SeriesCollection(1).HasDataLabels = True
ActiveChart.ChartArea.Border.LineStyle = False
ActiveChart.Location Where:=xlLocationAsObject, Name:="Evaluation"
With ActiveChart.Parent
.Left = 935
.Width = 650
.Top = 505
.Height = 225
End With
Set cht2 = Sheets("Evaluation").ChartObjects("Diagram 1").Chart
With cht2.Axes(xlCategory, xlPrimary)
.HasMajorGridlines = False
.HasMinorGridlines = False
End With
With cht2.Axes(xlValue, xlPrimary)
.HasMajorGridlines = False
.HasMinorGridlines = False
End With
With ActiveChart.SeriesCollection.NewSeries
.ChartType = xlLine
.Interior.Color = RGB(255, 0, 0)
.XValues = "=Evaluation!R9C21:R" & SourceLastrow1 & "C21"
.Values = "=Evaluation!R9C24:R" & SourceLastrow1 & "C24"
End With
End Sub
At the first run the code is working fine, just if I add new data to the source then the code add new series to chart (and change the colors also)... I do not why...
By the way if I run again the code (if data source not changed) the code give back the expected chart result.
The target would be that if the data source has been changed then (after the code run) the chart changing as well (without any bug).
Do you have some idea how could be avoid this kind of problem?
Thanks in advance the reply!