Duplicates removal/prevention in VBA ( New to VBA)

Oklahoma

New Member
Joined
Oct 17, 2017
Messages
2
Hi All:

it's actually my first post here, and I am practically new to VBA, so bare with me:).

I am running macros that import data from a .txt file, organize it, and then append the new data to historical data base.

Since I am running a macro of macros, and finally closing file and saving automatically ( ActiveWindow.Close savechanges:=True), I risk of running the same macro twice sending duplicates to the destination range.

So how can remove such duplicates using VBA( already have one duplicate), and how can I prevent duplicates within my current macro.

Much appreciated.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
You have a couple choices here that depends on how your data/imports are structured.

The main thing will be distinguishing a column (e.g transaction #), or a combination of columns (Account# + Date) that will be unique, and not overwritten.

a) You can have a check at the beginning of your macro, that checks if the first unique value from your import, already exists in the database. If it does, cancel the import, if not, continue and run the macro.

b) At the end of your import, you can use that unique column to remove duplicates. This would clean up your existing duplicates you already have.
 
Upvote 0
Wow that was quick. Thanks alot: let me try this and I'll get back if it works.

You have a couple choices here that depends on how your data/imports are structured.

The main thing will be distinguishing a column (e.g transaction #), or a combination of columns (Account# + Date) that will be unique, and not overwritten.

a) You can have a check at the beginning of your macro, that checks if the first unique value from your import, already exists in the database. If it does, cancel the import, if not, continue and run the macro.

b) At the end of your import, you can use that unique column to remove duplicates. This would clean up your existing duplicates you already have.
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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