- this excel sheet. columns g , column j have same values in different order.
- the code runs , moves values column j column h, beside same value of column g.
- the problem when there 2 values same moves first value finds in column h. value
747.00
in j:2 must move h:2 while value747.00
in j:5 must move h:6 not h:2.
this code:
dim cel range, cel2 range dim lastrow long lastrow = cells(rows.count, 10).end(xlup).row each cel in range(cells(1, 7), cells(lastrow, 7)) each cel2 in range(cells(1, 10), cells(lastrow, 10)) if cel2.value = cel.value cel.offset(0, 1).value = cel2.value cel2.value = "" end if next cel2 next cel
it sounds cycling through column j , looking match in column g. i've reversed cycling through column g , looking match in column j. once 1 match has been found moved on column h thereby removing column j.
sub match_em_up() dim rwg long, rwj long worksheets("sheet1") rwg = 2 .cells(rows.count, "g").end(xlup).row if cbool(application.countif(.columns("j"), .cells(rwg, "g").value2)) rwj = application.match(.cells(rwg, "g").value2, .columns("j"), 0) .cells(rwg, "h") = .cells(rwj, "j").value2 .cells(rwj, "j").clearcontents end if next rwg end end sub
before:
after:
Comments
Post a Comment