Form a circle (ie. color specific cells) given specific radius

G

Guest

I am trying to create a circle (ie. color specific cells in a spreadsheet)
based on a certain diameter (ie. 100 cells). This could be code (formula)
written in Visual Basic that would use the given diameter and automatically
selects cells to leave out of the circle (different color). I was wondering
if this is some way that has already been implemented previously or if there
is a formula (circle equation I believe, R^2 = X^2 + Y^2) that I could use in
VB and automatically apply it to spreadsheet cells and only color the cells
that would form a circle and leave other cells as is?

Your help is very much appreciated.
 
G

Guest

Thanks for your help Gary,
The problem I am having is not how to color cells , it is what cells to
automatically select to create a circle, so when I color them, I would be
able to see the circle shape.
I think that I will need to decide on the size of the cell (ie. 1point wide
cell = x inch), then how many cells would fit in my desired diameter based on
the width set for all cells, then have a formula that would exclude some of
the cells on the outside of my circle and color them.
I am thinking that this is a visual basic code that needs to include all the
parameters mentioned above (cell size, diameter (how many cells), formula to
decide what cells to exclude then color them(so the coloring is just to
differentiate between the included and excluded cells in order to form a
circle)
I was wondering if somebody has already implemented some code to create a
circle based on parameters mentioned above.

Regards,
Dave
 
G

Guest

This routine calculates the distance from CV1000 (the center) and colors
cells that are within a circle. Of course, column width must be adjusted to
give the circular appearance:


Sub asdf()
For i = 900 To 1100
For j = 50 To 150
d = Sqr((i - 1000) ^ 2 + (j - 100) ^ 2)
If d < 50 Then
Cells(i, j).Interior.ColorIndex = 46
End If
Next
Next
End Sub
 
G

Guest

Thanks gary, that worked.

Gary''s Student said:
This routine calculates the distance from CV1000 (the center) and colors
cells that are within a circle. Of course, column width must be adjusted to
give the circular appearance:


Sub asdf()
For i = 900 To 1100
For j = 50 To 150
d = Sqr((i - 1000) ^ 2 + (j - 100) ^ 2)
If d < 50 Then
Cells(i, j).Interior.ColorIndex = 46
End If
Next
Next
End Sub
 
G

Guest

Hi,
How easy would it be to save this circle selection (as a range) and have it
fit in excel spreadsheet window that would appear so I do not have to look
for it.
this is because the circle is going to be different size each time I run the
program with different circle dimensions.
Thanks for your help,
Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top