Results 1 to 3 of 3

Help with a pie-chart format in a VBA code

Threaded View

  1. #1
    Registered User
    Join Date
    03-16-2010
    Location
    Brasil
    MS-Off Ver
    Excel 2003
    Posts
    7

    Help with a pie-chart format in a VBA code

    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
    Last edited by Leosado; 03-16-2010 at 09:03 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1