Dear experts,

I´m in trouble with this project. Strange 'cause the same code works on a different workbook.
Can you guys help me, plz?

Sub Graph()

Dim y As Byte
Dim x As Byte
Dim a As Byte
Dim D As Integer

x = 0
y = 5

Workbooks("Graph1.xls").Activate
Worksheets("Plan1").Select

With ActiveSheet.ChartObjects("Graph 26").Activate

Do Until ActiveChart.SeriesCollection.Count = 0
ActiveChart.SeriesCollection(1).Delete
Loop

End With

Worksheets("Plan1").Select
a = Worksheets("Plan1").Range("U6")
a = a + 3


With ActiveChart

Do Until a = y

y = y + 1
D = y
x = y - 5

.SeriesCollection.NewSeries
.SeriesCollection(x).Name = Plan1.Cells(D, 18).Value
.SeriesCollection(x).Values = Plan1.Cells(D, 19).Value
.SeriesCollection(x).XValues = Plan1.Cells(D, 20).Value

Loop

End With

End Sub

.SeriesCollection(x).Name = Plan1.Cells(D, 18).Value
.SeriesCollection(x).Values = Plan1.Cells(D, 19).Value
.SeriesCollection(x).XValues = Plan1.Cells(D, 20).Value

that's the part that contain the error.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.