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:

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.

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:

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.

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

ASKER

Here the file.

Exp-double.xlsx

Exp-double.xlsx

ASKER CERTIFIED SOLUTION

membership

This solution is only available to members.

To access this solution, you must be a member of Experts Exchange.

ASKER

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:

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`

This is just to clear the sheet 2, I suppose.`dict.Item(x(i, 1)) = ""`

Why **= ""**?`n = Application.CountIf(rng, rng.Cells(1))`

Why the second argument is **rng.Cells(1)**? Is**(1)**an offset?This is just to clear the sheet 2, I suppose.Correct.

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

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

Why = "" ?

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.

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

Why the second argument is rng.Cells(1)? Is (1) an offset?

ASKER

Thanks for helping me.

You're welcome Paolo!