Link to home
Start Free TrialLog in
Avatar of Paolo Crossi
Paolo Crossi

asked on

VBA: manipulation duplicates in Excel

Hello everybody.

I've a task as follows:

1) sheet 1: consider duplicates in column 2
2) duplicates in column 2: check if they have different values in column 1
3) if they have different values in column 1, copy entire row in sheet 2.

Look at the example in the attachment:

User generated image
Beta, Gamma, Ics, Lambda and Omega have duplicates.
But only Gamma and Lambda have different values on column 1, so copy them on sheets 2.

Thank's for your help.
Avatar of Saqib Husain
Saqib Husain
Flag of Pakistan image

Can you upload this file instead of me typing this thing again so that I can test it?
Avatar of Paolo Crossi
Paolo Crossi

ASKER

Here the file.
Exp-double.xlsx
ASKER CERTIFIED SOLUTION
Avatar of Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj)
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry I'm late for the answer, but I've needed time to study the code you've proposed.

Put in practical terms, it seems to work (I've tested it 3-4 times with huger amount of data).

Now, the theory:

dws.Range("A2").CurrentRegion.Offset(2).Clear

Open in new window

This is just to clear the sheet 2, I suppose.



dict.Item(x(i, 1)) = ""

Open in new window

Why = "" ?



n = Application.CountIf(rng, rng.Cells(1))

Open in new window

Why the second argument is rng.Cells(1)? Is (1) an offset?
This is just to clear the sheet 2, I suppose.
dws.Range("A2").CurrentRegion.Offset(2).Clear
Correct.

dict.Item(x(i, 1)) = ""
Why = "" ?
Because we only need unique keys from Column B not their values.

n = Application.CountIf(rng, rng.Cells(1))
Why the second argument is rng.Cells(1)? Is (1) an offset?
No. The second argument in Countif is the value you are trying to count in the first argument rng. rng.Cells(1) would be the first cell in column A in the rows returned after applying the filter in column B.
Thanks for helping me.
You're welcome Paolo!