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
try just getting rid of the .select in your with statement
If you can't figure out how a formula works, try stepping through it using "Evaluate Formula" in the Formula Auditing menu item in the tools menu!
If you want to see where your code went wrong, try stepping through it by clicking in the code and pressing F8 and watch as the magic happens!
If you are happy with any of the results, please add to the contributor's reputation by clicking the blue scales icon in the blue bar of the post.
Actually, I thought taking the .select out would solved the issue, because that's what I did in my excel 2007 file. Although in this 2003 file, it happens the same run time error 91.
Any other idea?
Last edited by Leosado; 03-19-2010 at 08:14 AM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks