AutoShape Condition

jbfrank

Active Member
Joined
Oct 13, 2003
Messages
290
I have a cell that I would like to populate with a colored oval. There are only 3 colors I need (Red, Yellow, Green).

I would like cell A1 to populate with a Red Oval if the value in cell A2 is "R", a Yellow Oval if the value in A2 is "Y" and a Green Oval if the value in cell A2 is "G".

Any ideas?

Thanks in advance for any help.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Try the following code:

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> AddShapeInA1()
<SPAN style="color:#007F00">'</SPAN>
<SPAN style="color:#007F00">'</SPAN>
<SPAN style="color:#00007F">Dim</SPAN> MyShape <SPAN style="color:#00007F">As</SPAN> Shape
<SPAN style="color:#00007F">Dim</SPAN> ColIdx <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN>

<SPAN style="color:#00007F">Select</SPAN> <SPAN style="color:#00007F">Case</SPAN> Range("A2")
    <SPAN style="color:#00007F">Case</SPAN> "R"
        ColIdx = 10
    <SPAN style="color:#00007F">Case</SPAN> "Y"
        ColIdx = 13
    <SPAN style="color:#00007F">Case</SPAN> "G"
        ColIdx = 11
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Select</SPAN>

<SPAN style="color:#00007F">Set</SPAN> MyShape = ActiveSheet.Shapes.AddShape(msoShapeOval, 1.5, 0.75, 42.75, 10.5)
<SPAN style="color:#00007F">With</SPAN> MyShape
    .TopLeftCell = Range("A1")
    .Fill.ForeColor.SchemeColor = ColIdx
    .Fill.Visible = msoTrue
    .Fill.Solid
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
<SPAN style="color:#00007F">Sub</SPAN> Macro2()</FONT>


Post for feedback

Ciao :biggrin:
 
Upvote 0
This works great! But what if I actually want the oval to appear in another cell? I tried changing the cell value in the code, but no matter what, the oval always shows up in cell A1.
 
Upvote 0
These numbers

1.5, 0.75, 42.75, 10.5

are the left, top, width and height coordinates where the shape will appear. You could use

Range("G2").Left, Range("G2").Top, 42.75, 10.5

for example, to make it appear in G2.
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,008
Members
448,935
Latest member
ijat

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top