Remove duplicates based on multiple criteria (ID and Date)

johnnytominaga

New Member
Joined
Apr 27, 2018
Messages
19
Hey guys!

I'm working on a project that requires merging data from multiple workbooks into a single "master" workbook.
All files have the same number of columns and have been merged properly. That means all data is in the "master" workbook.

I couldn't manage to remove the duplicates though. They need to be removed based on multiple criteria and so that cells with value are copied even if the rest of the row is removed. The criteria that defines which duplicate is to be kept is:
a) ID No. (numerical)
b) Update Date (the higher is kept)

Dataset sample:

IDNameLocationPhoneLast updated on
1SaraMiami9999999919/07/2018
3Brian8888888815/03/2015
4JoshSeattle03/02/2015
7PeterNew York30/09/2016
7Peter6666666601/10/2016
3BrianLos Angeles8888888820/06/2017
7Peter20/01/2017
9Nicole5555555518/11/2016
47777777704/01/2017

<tbody>
</tbody>

Desired result:

IDNameLocationPhoneLast updated on
1SaraMiami9999999919/07/2018
3BrianLos Angeles8888888820/06/2017
4JoshSeattle7777777704/01/2017
7PeterNew York6666666620/01/2017
9Nicole5555555518/11/2016

<tbody>
</tbody>

I tried by using the Dictionary object, but couldn't get anywhere close to what I'm looking to achieve. Also, the script is going to be used in multiple PCs, so if I could avoid needing to activate the Microsoft Scripting Runtime everytime, that would be appreciated.

I'm using Excel 2016 on Windows.

Any ideas on how I could accomplish that?

Thanks a lot in advance.


Johnny
 
Don't understand why are you getting an error in
vData = .Range("A2:AA" & .Cells(.Rows.Count, "B").End(xlUp).Row)

It's a very simple code line that defines the variant array :confused:

M.
 
Upvote 0

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Tell us what you get in

Code:
With Sheets("Sheet1")
    MsgBox .Cells(.Rows.Count, "B").End(xlUp).Row
End with

M.
 
Upvote 0
Inserting an ID in cell B6901, say 4, worked perfectly for me
Sorry, i don't know why you are getting such error. Maybe someone else can help.

M.
 
Last edited:
Upvote 0
I believe the error happens depending on the content/amount of content on the table.
Do you know if there's a limit of how much data a variant can carry?

Nothing to be sorry about.
You were increadibly helpful.

Thanks again.


Inserting an ID in cell B6901, say 4, worked perfectly for me
Sorry, i don't know why you are getting such error. Maybe someone else can help.

M.
 
Upvote 0
I believe the error happens depending on the content/amount of content on the table.
Do you know if there's a limit of how much data a variant can carry?

As i said i tried with 6901 rows (as you did) and everything worked fine.
No limit that i'm aware to set a variant array. I did some google searches i couldn't find anything saying there is a limit.
But i may be wrong...

Try in a new workbook and see if it works

M.
 
Upvote 0
Hey!

Just an update that I've found out what was happening.
Some cells in the dataset I was testing had a "/" character (in the phones list). I believe that the script was treating that as a calculation to be made, which was what was causing it to crash.

I fixed that and it worked perfectly.

Thanks a lot Marcelo. You were right, there was nothing wrong with the code.
I couldn't have it made without your help.

Have a great day!


As i said i tried with 6901 rows (as you did) and everything worked fine.
No limit that i'm aware to set a variant array. I did some google searches i couldn't find anything saying there is a limit.
But i may be wrong...

Try in a new workbook and see if it works

M.
 
Upvote 0

Forum statistics

Threads
1,215,045
Messages
6,122,836
Members
449,096
Latest member
Erald

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top