ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to compare two sheet using vba and remove duplicate content? (https://www.excelbanter.com/excel-programming/432869-how-compare-two-sheet-using-vba-remove-duplicate-content.html)

geniusideas

How to compare two sheet using vba and remove duplicate content?
 
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







Patrick Molloy[_2_]

How to compare two sheet using vba and remove duplicate content?
 
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).Pastspeci al 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



"geniusideas" wrote:

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








Patrick Molloy[_2_]

How to compare two sheet using vba and remove duplicate conten
 
check for typos!

i had 'Pastspecial' and it should be Pastespecial

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


"Patrick Molloy" wrote:

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).Pastspeci al 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



"geniusideas" wrote:

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









All times are GMT +1. The time now is 04:55 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com