Is there a generic way to implement if status box true then turn row to green on Excel VBA? -


instead of specifying each checkbox name, , input parameters, there generic way implement row color change based on checkbox status?

say have function checks status of checkbox

function green(box1 string, row string) if activesheet.checkboxes(box1).value = xlon    range(row).interior.colorindex  = 4 else    range(row).interior.colorindex = 0 end if end function  sub checkbox1_click() application.run "green", "check box 1", "1:1" end sub 

the problem need define these 3 arguments time, , lets have shift set of items down, codes won't shift along

any idea how build more generic way implement checkbox changes row color without arguments indicating row it's in?

this assumes have 1 check box each row in worksheet, or that, , each checkbox should correspond row it's in.

instead of hard-coding row argument "1:1" in example, instead:

sub checkbox1_click()     application.run "green", "check box 1", _         activesheet.shapes("check box 1").topleftcell.row end sub sub checkbox2_click()     application.run "green", "check box 2", _         activesheet.shapes("check box 2").topleftcell.row end sub      function green(box1 string, row long) if activesheet.checkboxes(box1).value = xlon    rows(row).interior.colorindex  = 4 else    rows(row).interior.colorindex = 0 end if end function 

as long you've configured checkboxes move cells, should work no matter in terms of inserting rows/etc.

update comments

sometimes checkbox appears in 1 row .topleftcell property different row. because .topleftcell property top left corner of checkbox control's frame, not physical "checkbox" itself. selecting checkbox in design mode can show .topleftcell may in row 1 though checkbox appears in row 2. can verify debugging:

enter image description here


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -