excel - Move values duplicated between columns -


  1. this excel sheet. columns g , column j have same values in different order.

enter image description here

  1. the code runs , moves values column j column h, beside same value of column g.

enter image description here

  1. 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 value 747.00 in j:5 must move h:6 not h:2.

enter image description here enter image description here

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:

        enter image description here

after:

        enter image description here


Comments