# VBA plot circle • ### Question

• How to plot a circle in excel?

i seem to not be able to run this properly

i feel this should be easy, am i missing something from this code?

Sub circledrawer()
Dim x
Dim y
Dim r
Dim h
Dim k
h = 101
k = 101
r = 100
x = -r
y = 0

Do
y = Sqr(-(x ^ 2 - r ^ 2))
Cells(h + x, k + y).Value = "p"
Cells(h + x, k - y).Value = "p"
Cells(h - x, k + y).Value = "p"
Cells(h - x, k - y).Value = "p"
x = x + 1
Loop Until x > r - 1

x = 0
y = -r

Do
x = Sqr(-(y ^ 2 - r ^ 2))
Cells(h + x, y + k).Value = "p"
Cells(h + x, k - y).Value = "p"
Cells(h - x, k + y).Value = "p"
Cells(h - x, k - y).Value = "p"
y = y + 1
Loop Until y > r - 1
x = 0
y = 0

End Sub

where h and k are midpoint x,y

this seems to only plot for the first loop, and not the second. any ideas?

thanks

Monday, February 25, 2013 11:15 AM

### All replies

• Both loops work, but the results of the two almost coincide, so you hardly notice it. If you replace "p" with something else, e.g. "o", in the second loop, you'll see what happens.

Regards, Hans Vogelaar

Monday, February 25, 2013 3:51 PM