excel - How do I combine two private Worksheet_Change subs into one in VBA? -


i have code :

private sub worksheet_change(byval target range)      dim lastrow long     dim rnglist range      lastrow = cells(rows.count, "a").end(xlup).row      set rnglist = range("ab3").currentregion      if target.cells.count > 1 exit sub      on error resume next      if not intersect(target, range("b18:b19")) nothing  ' user in column-a         target.value = application.worksheetfunction.vlookup(target.value, rnglist, 2, false)     end if      set rnglist = nothing end sub 

and

private sub worksheet_change(byval target range)  dim lastrow long dim rnglist range  lastrow = cells(rows.count, "a").end(xlup).row  set rnglist = range("ac3").currentregion  if target.cells.count > 1 exit sub  on error resume next  if not intersect(target, range("b10:b11")) nothing  ' user in column-a     target.value = application.worksheetfunction.vlookup(target.value, rnglist, 2, false) end if  set rnglist = nothing 

end sub

i combine them can use both, don't know how without conflict, appreciated, thank you.

if understand correctly should trick trying do:

 private sub worksheet_change(byval target range)      worksheetchanged target, range("ac3").currentregion, range("b10:b11")     worksheetchanged target, range("ab3").currentregion, range("b18:b19")  end sub  private sub worksheetchanged( byval target range, byval rnglist range, byval intersectrng range )      dim lastrow long      lastrow = cells(rows.count, "a").end(xlup).row      if target.cells.count > 1 exit sub      on error resume next      if not intersect(target, intersectrng) nothing  ' user in column-a         target.value = application.worksheetfunction.vlookup(target.value, rnglist, 2, false)     end if      set rnglist = nothing end sub 

here have private function gets ranges parameters. can call function want (though excel might become bit slow if call in worksheed_change sub).


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -