Excel 2007 VBA find function. Trying to find data between two sheets and put it in a third sheet -
all,
i trying write macro search cells column 2 sheet1 in sheet2 , copy found rows sheet 2.
this have got far:
sub copyunique() application.displayalerts = false set qa_14 = sheets("qa 14feb") set prod_14 = sheets("prod 14feb") set prod_o14 = sheets("sheet1") counter = 1 dim found range dim qarange range row = 1 prod_14.usedrange.rows.count set qarange = qa_14.cells(2, 1) set found = qarange.find(what:=prod_14.cells(row, 2).text, after:=qa_14.range("a1"), lookin:=xlvalues, lookat:=xlpart, searchorder:=xlbycolumns, searchdirection:=xlnext, matchcase:=false, searchformat:=false) if not found nothing prod_14.usedrange.range(cells(row, 1), cells(row, prod_14.usedrange.columns.count)).copy prod_o14.range("a" & ltrim(str(counter))) counter = counter + 1 end if next end sub
the problem occurs on line find function. gives type mismatch error. have tried splitting variables separate line they're not part of problem.
any ideas?
thanks
the after parameter you're using invalid. remove , won't receive type mismatch error anymore. first question answered, , have other... i'm checking how can set value properly.
i believe maybe if give better explanation of you're trying achieve improve our assistance giving suggestions.
rgds
edit:
it seems after needs within range being searched (and believe that's not want).
this code not raise errors, although believe not want either. if give better example of need, may able further.
tip #1: next time when submitting code, i'd ask include in code declaration of variables you're using (you're using option explicit, right?). specially in type mismatch errors, variable type may cause problem.
tip #2: i'd suggest take on hungarian notation.
sub test() dim qa_14 worksheet dim prod_14 worksheet dim prod_o14 worksheet dim icounter integer dim irow integer dim rngafter excel.range dim rngwhat excel.range dim found range dim qarange range set qa_14 = sheets("qa 14feb") set prod_14 = sheets("prod 14feb") set prod_o14 = sheets("sheet1") icounter = 1 irow = 1 prod_14.usedrange.rows.count set qarange = qa_14.cells(2, 1) set rngafter = qarange.cells(1, 1) set found = qarange.find(what:=prod_14.cells(irow, 2).text, after:=rngafter, lookin:=xlvalues, lookat:=xlpart, searchorder:=xlbycolumns, searchdirection:=xlnext, matchcase:=false, searchformat:=false) if not found nothing prod_14.usedrange.range(cells(irow, 1), cells(irow, prod_14.usedrange.columns.count)).copy prod_o14.range("a" & ltrim(str(icounter))) icounter = icounter + 1 end if next end sub
Comments
Post a Comment