Hi all,
My doubt is probably simple for most of you, but I'm pretty new at this so, better to ask you than keep looking through google.
I've edited a code in word to create a pie chart and format it according the name of the colors using the select case. When this code is run in a excel 2007 it runs pretty good, but once I write the same code in a excel 2003, it gives me a runtime error which say: "Object variable or With block variable not set". below in the code I show where this message appears.
My problem is right in this section, how do I solve this issue in excel 2003, once in excel 2007 is working properly.
Thanks in advance
The code is:
Sub Pie_Chart()
'Choosing what type of chart
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xl3DPieExploded
ActiveChart.ApplyLayout (6)
ActiveChart.ChartArea.Select
'Creating the Chart
With ActiveChart.SeriesCollection.NewSeries
.Name = ActiveSheet.Range("C2")
.Values = ActiveSheet.Range("C8:C10")
.XValues = ActiveSheet.Range("B8:B10")
End With
'Placing the Chart
With ActiveChart.Parent
.Left = 1
.Width = 215
.Top = 267
.Height = 150
End With
'Formating the Chart
Dim iPoint As Long, nPoint As Long
With ActiveChart.SeriesCollection(1).Select 'THE RUN TIME ERROR ON EXCEL 2003 COMES RIGHT HERE
For iPoint = 1 To .Points.Count
Select Case WorksheetFunction.Index(.XValues, iPoint)
Case "Yellow"
.Points(iPoint).Interior.ColorIndex = 6 ' Yellow
Case "Red"
.Points(iPoint).Interior.ColorIndex = 3 ' Red
Case "Green"
.Points(iPoint).Interior.ColorIndex = 4 ' Green
End Select
Next
End With
End Sub
Bookmarks