excel vba - Change Shape Colour when Cell is Clicked -


i looking code change colour of shape when cell clicked on. example shape s_irl ireland , located in cell b22.

what happen if cell b22 shape s_irl changes blue red. if cell country clicked corresponding shape changes red , previous returns previous colour. appreciated enter image description here

you can add new subroutine in worksheet's code fire when selection changes on sheet:

private sub worksheet_selectionchange(byval target range)      dim strshapename string 'variable hold shape name     dim shp shape 'variable hold shape object      'detect if click in range a:c     if not intersect(target, range("a:c")) nothing          'boom... set shapes blue         each shp in me.shapes              if left(shp.name, 2) = "s_" shp.fill.forecolor.rgb = rgb(0, 0, 255)         next shp                  'grab shape name column         strshapename = cells(target.row, 1).value          'set color of shape red         shapes(strshapename).fill.forecolor.rgb = rgb(255, 0, 0)     end if end sub 

this detect if selection change cell in columns a, b, or c. if grab name of shape column , set color of shape red.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -