我正在尝试将单个单元格添加到图表中,以便仅将满足特定条件的单元格添加到图表中。
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
当我运行代码时,Excel 会引发以下错误:Run-time error '1004': Application-defined or object-defined error.
它在线上这样做: ActiveChart.SeriesCollection(1).XValues = ChartXDataString
即使当我录制添加单个单元格的宏时,图表仍然有效,直到我运行录制的宏,它会抛出错误。
帮助将不胜感激!