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:
insert line @ top:
option explicit
dim rangeobj:
dim rangeobj range
introduce variable storing text
.find():dim rangestr string
replace
set rangeobj = activeworkbook.cells(1, "a")rangestr = activeworkbook.cells(1, "a").valuereplace
cells.find(what:=rangeobj,cells.find(what:=rangestr,
let's see brings.
Comments
Post a Comment