Excel Find VBA is not working -


here code tried. stuck in finding cell (set rangeobj = cells.find).

please check following code:

sub copyfromfile() dim myfile string dim erow dim filepath string filepath = "c:\users\nazmul hossain akash\desktop\play excel\final\" myfile = dir(filepath) while len(myfile) > 0     if myfile = "zmaster.xlsm"         exit sub     end if      workbooks.open (filepath & myfile)     range("b2:d18").copy     set rangeobj = cells(1, "a")     activeworkbook.close      set rangeobj = cells.find(what:=rangeobj, after:=activecell, _     lookin:=xlformulas, lookat:=xlpart, searchorder:=xlbyrows, _     searchdirection:=xlnext, matchcase:=false)      if rangeobj nothing msgbox "not found" else rangeobj.select     activecell.offset(rowoffset:=2, columnoffset:=0).activate      activesheet.pastespecial      myfile = dir loop end sub 

i think see problem. still not dim rangeobj (and see no option explicit @ top! - please add it). make dim every variable, therefore have decide data type variable be, including rangeobj. , rangeobj here problem. since set rangeobj = cells.find(), it's ok have range object. however, before set rangeobj = activeworkbook.cells(1, "a") - set it. , mistake, because way object, , after want use in .find(). should pass .find(), not object. let's try fixing problem:

  1. insert line @ top:

    option explicit
  2. dim rangeobj:

    dim rangeobj range
  3. introduce variable storing text .find():

    dim rangestr string
  4. replace set rangeobj = activeworkbook.cells(1, "a") rangestr = activeworkbook.cells(1, "a").value

  5. replace cells.find(what:=rangeobj, cells.find(what:=rangestr,

let's see brings.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -