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:

double.png
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

Avatar of undefined
Last Comment
Subodh Tiwari (Neeraj)

8/22/2022 - Mon
Saqib Husain

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

Here the file.
Exp-double.xlsx
ASKER CERTIFIED SOLUTION
Subodh Tiwari (Neeraj)

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
Sign up - Free for 7 days
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.
See how we're fighting big data
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 question
ASKER
Paolo 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:

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?
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.
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.
ASKER
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.