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.

VBA* duplicateMicrosoft ExcelMicrosoft Office

Saqib Husain

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

Paolo Crossi

Here the file.

Exp-double.xlsx

Log in or sign up to see answer

Become an EE member today7-DAY FREE TRIAL

Members can start a 7-Day Free trial then enjoy unlimited access to the platform

or

Learn why we charge membership fees

We get it - no one likes a content blocker. Take one extra minute and find out why we block content.

Not exactly the question you had in mind?

Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.

ask a questionPaolo Crossi

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:

**= ""** ?

**rng.Cells(1)**? Is **(1)** an offset?

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 Your help has saved me hundreds of hours of internet surfing.

fblack61

Subodh Tiwari (Neeraj)

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?

Paolo Crossi

Thanks for helping me.

Subodh Tiwari (Neeraj)

You're welcome Paolo!

Get an unlimited membership to EE for less than $4 a week.

Unlimited question asking, solutions, articles and more.