VBA Event help, change shape of color as per option selections

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
983
Office Version
  1. 2010
Platform
  1. Windows
Hi Team

Need vba help,

Task is if I click on Fruits option Shape of color should be blue
if I click on Vegetables option Shape of Color should be Red

I have linked cell into Range("a1") value

There is single shape. just for reference two shapes shown . how to achieve this , I tried no luck


1708520133492.png
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Here is one way:: Assign this macro to both option buttons:

VBA Code:
Sub Macro()
    With ActiveSheet.Shapes("rectangle 1").Fill.ForeColor  '<< change shape name to suit.
        If UCase(ActiveSheet.Shapes(Application.Caller).OLEFormat.Object.Text) = "FRUITS" Then
            .RGB = RGB(0, 0, 255)
        Else
            .RGB = RGB(255, 0, 0)
        End If
    End With
End Sub
 
Upvote 0
Hi Jaafar,

Thanks for your help, I am looking for an event to occur
if clicks on option buttons ............... color of shape should get changed. I dont want to assign a macro

otherwise I have to assign two macros on below option button


1) fruits button
2) Vegetables button
 
Upvote 0
Clicking on the option buttons won't raise the worksheet_change event even if you link the option buttons to a a cell like you did.

Simply assign the macro I posted to both option buttons and when you click on either of them, the shape will change color as required.

PS: Make sure to edit the shapes name in the code to suit.

Also, you won't need the link cell anymore if you go down this route.
 
Upvote 0
Hi Jaafar,

Thanks for your help, code is working, otherwise I would have kept searching on event.

So assigned Macro and code is working now.


Thanks
mg
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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