excel - Using rangefind -
i have 3 sheets, sheet s, sheet p , sheet data.
i first copy column of sheet s sheet data. in column e of sheet data, id. id in column e of data sheet, matches column of p sheet, copy corresponding id.
the problem here sheet data contains 214 rows, while sheet p contains 1110. while comparing id, there 2 different id row 870 , 871, not copied, though same.
could guide reason ?
sub lookup() dim llastrow, totalrows long dim rng range dim long 'copy lookup values s data sheets("s") llastrow = .cells(.rows.count, 1).end(xlup).row .range("p5:p" & llastrow).copy destination:=sheets("data").range("e5") .range("g5:g" & llastrow).copy destination:=sheets("data").range("h5") end totalrows = sheets("p").cells(sheets("p").rows.count, "a").end(xlup).row = 5 llastrow 'search value on p_apqp sheets("p") set rng = .columns(1).find(sheets("data").cells(i, 5).value & "*", lookat:=xlwhole) end 'if found put value on destination sheet if not rng nothing sheets("data") .cells(i, 6).value = rng.value .cells(i, 1).value = rng.offset(0, 1).value .cells(i, 2).value = rng.offset(0, 2).value .cells(i, 3).value = rng.offset(0, 3).value .cells(i, 4).value = rng.offset(0, 9).value .cells(i, 9).value = rng.offset(0, 10).value .cells(i, 13).value = rng.offset(0, 6).value .cells(i, 14).value = rng.offset(0, 5).value .cells(i, 15).value = rng.offset(0, 4).value .cells(i, 16).value = rng.offset(0, 8).value end end if next end sub
i'll post whole code. made adjustment first line of declarations - had it, totalrows being declared long. have spell each 1 out i'm afraid.
sub lookup() dim llastrow long, totalrows long dim rng range dim long sheets("s") llastrow = .cells(.rows.count, 1).end(xlup).row .range("p5:p" & llastrow).copy destination:=sheets("data").range("e5") .range("g5:g" & llastrow).copy destination:=sheets("data").range("h5") end totalrows = sheets("p").cells(sheets("p").rows.count, "a").end(xlup).row = 5 llastrow 'search value on p_apqp sheets("p") 'amended below set rng = .columns(1).find(trim(sheets("data").cells(i, 5).value) & "*", lookat:=xlwhole) end 'if found put value on destination sheet if not rng nothing sheets("data") .cells(i, 6).value = rng.value .cells(i, 1).resize(, 3).value = rng.offset(0, 1).value .cells(i, 2).value = rng.offset(0, 2).value .cells(i, 3).value = rng.offset(0, 3).value .cells(i, 4).value = rng.offset(0, 9).value .cells(i, 9).value = rng.offset(0, 10).value .cells(i, 13).value = rng.offset(0, 6).value .cells(i, 14).value = rng.offset(0, 5).value .cells(i, 15).value = rng.offset(0, 4).value .cells(i, 16).value = rng.offset(0, 8).value end end if next end sub
Comments
Post a Comment