excel - Multiple targets with different macro calls in worksheet_change VBA code -


i use worksheet_change() run macro1 if cell1 changed, macro2 if cell2 changed, etc. understand worksheet_change() allows target , sh, , 1 sub can used. thought run like:

private sub targets(byval target range) select case target.address case "cell1" call sheetchange.macro1 case "cell2" call sheetchange.macro2 case "cell3" call sheetchange.macro3 end select end sub 

but, apparently cannot! tried

private sub targets(byval target range) if target.address="cell1" call sheetchange.macro1 elseif target.address="cell2" call sheetchange.macro2 elseif target.address="cell3" call sheetchange.macro3 end if end sub 

but no luck there either. help?

see example. have use intersect check if particular cell changed or not. taking example of a1, a2 , a3

i recommend looking @ link tells need take care of when working worksheet_change

private sub worksheet_change(byval target range)     on error goto whoa      application.enableevents = false      if not intersect(target, range("a1")) nothing         '~~> run macro here     elseif not intersect(target, range("a2")) nothing         '~~> run macro here     elseif not intersect(target, range("a3")) nothing         '~~> run macro here     end if  letscontinue:     application.enableevents = true     exit sub whoa:     msgbox err.description     resume letscontinue end sub 

you might want handle situations user copies , pastes multiple cells. in such scenario, use check , act appropriately.

    '~~> excel 2003     if target.count > 1      end if      '~~> excel 2007 +             if target.countlarge > 1      end if 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -