How to compare two sheet using vba and remove duplicate content?

G

geniusideas

Hi, need urgent help
I have 2 sheets need to compare and delete duplicate content using VBA
For Example :
Before
Sheet1
A B C
222 Diode D506
333 Capasitor C123 - duplicate row
132 Transistor T525
555 Coil CL121 - duplicate row

Sheet2
333 Capasitor C123 - duplicate row
555 Coil CL121 - duplicate row
555 Coil CL121 - duplicate row x 2
444 Diode D444
444 Transistor T444

After
Sheet1
222 Diode D506
132 Transistor T525

Sheet2
444 Diode D444
444 Transistor T444
555 Coil CL121

Meaning I have to remove duplicate row inbetween sheet1 and sheet2
base on one to one.
Pls help to give me VBA code on how to do.
Thanks
 
P

Patrick Molloy

its easy if you haev everything in one sheet

'select table to copy
sheet2.Range("A1").CurrentRegion.Copy
'now paste it below existing data
Sheet1.Range("A1").End(xldown).Offset(1).Pastspecial xlall
application.cutcopymode = false
'sort the new table off column A
range("A1").Sort Range("A1")
' remove duplicates
for rw = range("A1").end(xldown).row to 2 step -1
if cells(rw,1) = cells(rw-1,1) then
rows(rw).delete
end if
next
 
P

Patrick Molloy

check for typos!

i had 'Pastspecial' and it should be Pastespecial

use Edit/Compile before runnign code.
sorry, I'm in a hurry ;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top