excel - Extracting a particular information from a cell -
i have sheet, s , p. in sheet s, have few id starting d2e , few id starting 4 in column n.
i comparing id, containing 4, sheet p in column l. if match, writing id of sheet p column in column n.
i have few case below in snapshot, not able extract. 1 me , how can that
in sheet s , have id 41035036_drw_000_draf , in sheet p able find corresponding d2e number , got printed, want number printed in sheet s of column p.
i believe need modify rng.find function. looks first 8 character. 1 help, how can that
below code
sub drwmatch() dim sh1 worksheet, sh2 worksheet dim cell range, cell2 range, lstcl variant, lstcl2 variant, rgfnd variant dim n double, id string dim string dim b variant set sh1 = thisworkbook.sheets("s") set sh2 = thisworkbook.sheets("p") ' id starts number 4 id = "4" lstcl = sh1.range("n10000").end(xlup).row lstcl2 = sh2.range("l10000").end(xlup).row 'comparing columns n , l in both sheets each cell in sh2.range("l5:l" & lstcl2) n = 5 lstcl = left(sh1.range("n" & n), 8) if cell = 'the cell in column m next matching cell equal 4xxxxxxx number cell.offset(0, 1) = 'the next cell in column n equal a2c number in column cell.offset(0, 2) = cell.offset(0, -11) end if next next 'test each cell in first sheet corresponds located results in second sheet _ 'and pastes a2c number, using range.find function each cell2 in sh1.range("n5:n" & n) if left(cell2, 1) = id set rgfnd = sh2.range("m5:m" & lstcl2).find(cell2.value) if not rgfnd nothing cell2.offset(0, 1) = sh2.range(rgfnd.address).offset(0, 1) end if end if next end sub
to have search on first 8 chars write find instruction this
set rgfnd = sh2.range("m5:m" & lstcl2).find(left(cell2.value, 8), lookat:=xlpart)
Comments
Post a Comment