I'm trying to add individual cells to a chart so that only cells that meet a certain criteria are added to the chart.
ChartXDataString = "="
ChartFuelDriveDataString = "="
For i = 0 To 5
If Range("AP" & FirstDataRow + i) <> "0" Then
If i = 5 Then
ChartXDataString = ChartXDataString & "'RAW FleetData'!$A$" & (FirstDataRow + i)
ChartFuelDriveDataString = ChartFuelDriveDataString & "'RAW FleetData'!$AP$" & (FirstDataRow + i)
Else
ChartXDataString = ChartXDataString & "'RAW FleetData'!$A$" & (FirstDataRow + i) & ";"
ChartFuelDriveDataString = ChartFuelDriveDataString & "'RAW FleetData'!$AP$" & (FirstDataRow + i) & ";"
End If
End If
Next i
ActiveSheet.ChartObjects("gFMP_TotalFuelLiters").Activate
ActiveChart.SeriesCollection(1).XValues = ChartXDataString
ActiveChart.SeriesCollection(1).Values = ChartFuelDriveDataString
When I run the code Excel throws the following error: Run-time error '1004': Application-defined or object-defined error.
It does so on the line: ActiveChart.SeriesCollection(1).XValues = ChartXDataString
Even when I record a macro adding individual cells, the chart works until I run the recorded macro, where it throws the error.
Help would be much appreciated!
ChartXDataString
when the error raises? – David Zemens.values
and.xvalues
properties ofSeriesCollection object
. Try to use.Formula
property but change the way you create yourchartXDataString or CharterFuelDriveDataString variables
. – Kazimierz Jawor