run time error 91 : Object Variable or With block variable not set in excel 2013 -


i have macro :

sheets("amend estimate").select  cells.find(what:=sheets("amend quote").range("g4").value, after:=activecell, lookin:=xlvalues, _     lookat:=xlpart, searchorder:=xlbyrows, searchdirection:=xlnext, _     matchcase:=false, searchformat:=false).activate  activecell.offset(41, 3).select  selection.copy  sheets("amend quote").select  range("g4").offset(14, 0).select  selection.pastespecial paste:=xlpastevalues, operation:=xlnone, skipblanks _     :=false, transpose:=false   '#2   sheets("amend estimate").select  cells.find(what:=sheets("amend quote").range("h4").value, after:=activecell, lookin:=xlvalues, _     lookat:=xlpart, searchorder:=xlbyrows, searchdirection:=xlnext, _     matchcase:=false, searchformat:=false).activate  activecell.offset(41, 3).select  selection.copy  sheets("amend quote").select  range("h4").offset(14, 0).select  selection.pastespecial paste:=xlpastevalues, operation:=xlnone, skipblanks _     :=false, transpose:=false   '#3   sheets("amend estimate").select  cells.find(what:=sheets("amend quote").range("i4").value, after:=activecell, lookin:=xlvalues, _     lookat:=xlpart, searchorder:=xlbyrows, searchdirection:=xlnext, _     matchcase:=false, searchformat:=false).activate  activecell.offset(41, 3).select  selection.copy  sheets("amend quote").select  range("i4").offset(14, 0).select  selection.pastespecial paste:=xlpastevalues, operation:=xlnone, skipblanks _     :=false, transpose:=false 

as have seen, macro finds range amend quote inside amend estimate(worksheets), gets value , pastes in offset cell in amend quote.

this working fine, throwing run time error 91.

can please me.

the issue find isn't finding anything. need put bit of error handling account when find returns no result, setting result of find action variable , doing activate on variable if there's there.

something this:

edit - updated code below including behaviour allow sub exit if search term isn't found or if search term 0 length string.

i've tidied code lot remove 'select manipulate' - can manipulate cells without selecting them first, it'll save lot of processing time.

finally i've condensed whole 50 iterations single loop rather repeating same action 50 times changing cell reference 1 column each time.

please remember accept answer correct if helps you.

sub test()  dim rng range dim aest worksheet, aquo worksheet  'set sheet names variables easier referencing set aest = sheets("amend estimate") set aquo = sheets("amend quote")  = 7 57 '7 = column h, 8 = column g, etc.      'set address of found value rng variable     set rng = aest.cells.find(what:=aquo.cells(4, i).value, after:=activecell, lookin:=xlvalues, _     lookat:=xlpart, searchorder:=xlbyrows, searchdirection:=xlnext, _     matchcase:=false, searchformat:=false)      if not rng nothing 'check if search term (from quote sheet) found in target sheet (estimate)          if not rng = "" 'check if search term 0 length string              rng.offset(41, 3).copy 'copy cell 41 rows down , 3 columns across             aquo.cells(4, i).offset(14, 0).pastespecial paste:=xlpastevalues 'paste cell 14 rows below original search term in quote sheet          elseif rng = "" 'exit sub if search term 0 length string             msgbox "work done"             exit sub         end if      elseif rng nothing 'exit sub if search term not found in target sheet         msgbox "work done"         exit sub      end if  next 'move next column across , loop  end sub 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -