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:
Code: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
Last edited by Leosado; 03-16-2010 at 10:03 PM.
Remove the Select, it's not required in any version.
Code:With ActiveChart.SeriesCollection(1) 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
Hi Andy,
I just took the select from the statement you said and the error keeps showing in the same place.!! Actually I've tryed that too, but it did not work.
Other sugestion, or a new code for that?
Thanks in advance
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks