1

我正在尝试将单个单元格添加到图表中,以便仅将满足特定条件的单元格添加到图表中。

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

即使当我录制添加单个单元格的宏时,图表仍然有效,直到我运行录制的宏,它会抛出错误。

帮助将不胜感激!

4

1 回答 1

0

结果是宏记录器以错误的格式记录。而不是像记录器所做的那样,ChartXDataString = "='RAW FleetData'!$A$2;'RAW FleetData'!$A$3;'RAW FleetData'!$A$4",正确的格式是 "=('RAW FleetData '!$A$2,'RAW FleetData'!$A$3,'RAW FleetData'!$A$4)" 带括号和逗号分隔符

于 2013-07-09T06:50:26.657 回答