I intended to update a chart with a macro based on some tabular data. The code in VBA is:
Dim rowNumber As Integer
Windows("Book1.xls").Activate
With Worksheets("Sheet1")
.ChartObjects(1).Activate
.ChartObjects(1).Chart.HasTitle = True
ActiveChart.ChartTitle.Select
Selection.Characters.Text = "MY CHART"
.ChartObjects(1).Select
ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection(1).XValues = .Range(Cells(8, 1), _
Cells(rowNumber, 1)).Address(ReferenceStyle:=xlR1C1)
ActiveChart.SeriesCollection(1).Values = .Range(Cells(8, 3), _
Cells(rowNumber, 3)).Address(ReferenceStyle:=xlR1C1)
ActiveChart.SeriesCollection(2).XValues = .Range(Cells(8, 1), _
Cells(rowNumber, 1)).Address(ReferenceStyle:=xlR1C1)
ActiveChart.SeriesCollection(2).Values = .Range(Cells(8, 66), _
Cells(rowNumber, 1)).Address(ReferenceStyle:=xlR1C1)
End With
But when the code reaches the line which assigns XValues to the SeriesCollection(1) I get a run-time error "Method 'Cells' of object '_Global' failed. Any idea how to modify the code?
This message was edited by corni on 2002-03-05 18:44
Dim rowNumber As Integer
Windows("Book1.xls").Activate
With Worksheets("Sheet1")
.ChartObjects(1).Activate
.ChartObjects(1).Chart.HasTitle = True
ActiveChart.ChartTitle.Select
Selection.Characters.Text = "MY CHART"
.ChartObjects(1).Select
ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection(1).XValues = .Range(Cells(8, 1), _
Cells(rowNumber, 1)).Address(ReferenceStyle:=xlR1C1)
ActiveChart.SeriesCollection(1).Values = .Range(Cells(8, 3), _
Cells(rowNumber, 3)).Address(ReferenceStyle:=xlR1C1)
ActiveChart.SeriesCollection(2).XValues = .Range(Cells(8, 1), _
Cells(rowNumber, 1)).Address(ReferenceStyle:=xlR1C1)
ActiveChart.SeriesCollection(2).Values = .Range(Cells(8, 66), _
Cells(rowNumber, 1)).Address(ReferenceStyle:=xlR1C1)
End With
But when the code reaches the line which assigns XValues to the SeriesCollection(1) I get a run-time error "Method 'Cells' of object '_Global' failed. Any idea how to modify the code?
This message was edited by corni on 2002-03-05 18:44