user3702974
user3702974

Reputation: 11

Circle around a point in the chart

I have a (x,y) coordinate which will be plotted in a scatter plot. I need a circle of radius R to be drawn around the point plotted.

Thanks and Regards, Prabhu.C

Upvotes: 1

Views: 3119

Answers (1)

barryleajo
barryleajo

Reputation: 1952

A 'bare bones' example which may get you started. You will need to play with scaling, units and positioning etc. to suit your context.

This will draw a circle with no fill and a red circumference, with a commented-out line to give it a solid fill (change .Visible to msoTrue).

enter image description here

Sub drawCircle()
Dim ws As Worksheet
Dim cLeft As Long, cTop As Long
Dim cX As Long, cY As Long, cDia As Long
Dim c1 As Shape

Set ws = Sheets("Sheet1")
cX = Range("A2")
cY = Range("B2")
cDia = Range("C2").Value * 2

cLeft = cX - (cDia / 2)
cTop = cY - (cDia / 2)

    With ws
        Set c1 = .Shapes.AddShape(msoShapeOval, cLeft, cTop, cDia, cDia)
            With c1
                .Fill.Visible = msoFalse
                .Line.Weight = 2
                .Line.ForeColor.RGB = RGB(255, 0, 0)
                '.Fill.ForeColor.RGB = RGB(255, 0, 0)  'eg Red fill
            End With
    End With

End Sub

Upvotes: 1

Related Questions