0
Dim cht As Chart
Dim Xleft As Double, Ytop As Double
Xleft = cht.PlotArea.InsideLeft

i am getting this error on the third line. does anyone know why?

here is the full code. please keep in mind that this is excel 2003

Sub DrawSmoothTransparentShapesOnRadarChart()
      Dim cht As Chart
      Set cht = Worksheets(1).ChartObjects(1)

      Dim srs As Series
      Dim iSrs As Long
      Dim Npts As Integer, Ipts As Integer
      Dim myShape As Shape
      Dim Xnode As Double, Ynode As Double
      Dim Rmax As Double, Rmin As Double
      Dim Xleft As Double, Ytop As Double
      Dim Xwidth As Double, Yheight As Double
      Dim dPI As Double
      Dim iFillColor As Long
      Dim iLineColor As Long

      Set cht = ActiveChart
      Xleft = cht.PlotArea.InsideLeft
      Xwidth = cht.PlotArea.InsideWidth
      Ytop = cht.PlotArea.InsideTop
      Yheight = cht.PlotArea.InsideHeight
      Rmax = cht.Axes(2).MaximumScale
      Rmin = cht.Axes(2).MinimumScale
      dPI = WorksheetFunction.Pi()

      For iSrs = 1 To cht.SeriesCollection.Count

        Set srs = cht.SeriesCollection(iSrs)

        Select Case srs.ChartType
          Case xlRadar, xlRadarFilled, xlRadarMarkers

            Npts = srs.Points.Count

            Xnode = Xleft + Xwidth / 2 * _
                (1 + (srs.Values(Npts) - Rmin) / (Rmax - Rmin) _
                * Sin(2 * dPI * (Npts - 1) / Npts))

            Ynode = Ytop + Yheight / 2 * _
                (1 - (srs.Values(Npts) - Rmin) / (Rmax - Rmin) _
                * Cos(2 * dPI * (Npts - 1) / Npts))

            With cht.Shapes.BuildFreeform _
                (msoEditingAuto, Xnode, Ynode)
              For Ipts = 1 To Npts

                Xnode = Xleft + Xwidth / 2 * _
                    (1 + (srs.Values(Ipts) - Rmin) / (Rmax - Rmin) _
                    * Sin(2 * dPI * (Ipts - 1) / Npts))

                Ynode = Ytop + Yheight / 2 * _
                    (1 - (srs.Values(Ipts) - Rmin) / (Rmax - Rmin) _
                    * Cos(2 * dPI * (Ipts - 1) / Npts))

                .AddNodes msoSegmentLine, msoEditingAuto, _
                    Xnode, Ynode
              Next
              Set myShape = .ConvertToShape
            End With

            For Ipts = 1 To Npts
              myShape.Nodes.SetEditingType 3 * Ipts - 2, msoEditingSmooth
            Next

            Select Case iSrs
              Case 1
                iFillColor = 44
                iLineColor = 12
              Case 2
                iFillColor = 45
                iLineColor = 10
              Case 3
                iFillColor = 43
                iLineColor = 17
            End Select

            With myShape
              .Fill.ForeColor.SchemeColor = iFillColor
              .Line.ForeColor.SchemeColor = iLineColor
              .Line.Weight = 1.5
              .Fill.Transparency = 0.5
            End With
        End Select
      Next

    End Sub

1 Answer 1

2

You need to set cht to a chart object.

EDIT In the light of the code above, I think you will find that your problems go away if you select a chart.

Sub DrawSmoothTransparentShapesOnRadarChart()
      Dim cht As Chart
      ''Delete this line, or comment it:
      ''Set cht = Worksheets(1).ChartObjects(1)

      Dim srs As Series
      Dim iSrs As Long
      Dim Npts As Integer, Ipts As Integer
      Dim myShape As Shape
      Dim Xnode As Double, Ynode As Double
      Dim Rmax As Double, Rmin As Double
      Dim Xleft As Double, Ytop As Double
      Dim Xwidth As Double, Yheight As Double
      Dim dPI As Double
      Dim iFillColor As Long
      Dim iLineColor As Long

      ''This line set cht equal to the selected chart
      Set cht = ActiveChart
Sign up to request clarification or add additional context in comments.

8 Comments

it says unable to get chartobjects property of the worksheets class
Do you have a chart on worksheet1? You can change (1) to the name of the worksheet and the name of the chart, for example, ("Sheet1").
thank you. i did not have a chart. i added a chart. and now it says TYPE MISMATCH on the same line
What chart type are you using? I have tried two versions of Excel and it works.
Just for the sake of experiment, create, say, a barchart from scratch data and then try.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.