image - Switch-Hide pictures based on cell values -
i not expert on vba, know based on browsing internet, simple codes work me well.
i switching pictures based on p52 value, works perfectly, want swich different pictures based on cell value p117 , part of code not work me. missing in code?
private sub worksheet_change(byval target range) application.screenupdating = false if target.address <> "$p$52" exit sub activesheet select case target.value case "horizontal - feet" .pictures("b3a").visible = true .pictures("v1a").visible = false .pictures("v1af").visible = false case "vertical - simple" .pictures("b3a").visible = false .pictures("v1a").visible = true .pictures("v1af").visible = false case "vertical - lantern" .pictures("b3a").visible = false .pictures("v1a").visible = false .pictures("v1af").visible = true end select end if target.address <> "$p$117" exit sub activesheet select case target.value case "right" .pictures("3p1").visible = true .pictures("3p1m").visible = false case "left" .pictures("3p1").visible = false .pictures("3p1m").visible = true end select end end sub thanks help.
think through logic of if statements causing exit sub.
if cell p117, hit first if statement causes exit sub immediately. never second check.
embed logic each of operations in if statements show here , able "do if cell range p52 or p117" bit more appropriately.
private sub worksheet_change(byval target range) application.screenupdating = false 'only following operation if cell address p52 - don't exit out 'of entire code if it's not if target.address = "$p$52" activesheet select case target.value case "horizontal - feet" .pictures("b3a").visible = true .pictures("v1a").visible = false .pictures("v1af").visible = false case "vertical - simple" .pictures("b3a").visible = false .pictures("v1a").visible = true .pictures("v1af").visible = false case "vertical - lantern" .pictures("b3a").visible = false .pictures("v1a").visible = false .pictures("v1af").visible = true end select end end if 'you skip down here if not p52, lets check again 'see if it's p117 if target.address = "$p$117" activesheet select case target.value case "right" .pictures("3p1").visible = true .pictures("3p1m").visible = false case "left" .pictures("3p1").visible = false .pictures("3p1m").visible = true end select end end if end sub if going have lot of checks this, may want create select case statement target.address too. it's hard better given you've asked here.
Comments
Post a Comment