+ Reply to Thread
Results 1 to 7 of 7

VBA to compare two Files and Delete duplicate

  1. #1
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    VBA to compare two Files and Delete duplicate

    Team,

    Need help here to understand the way how to do it.

    1. I have two files.
    2. Both files has data in it.
    3. I am trying to compare each line and delete the duplicate in File 2.
    4. Save the File 2 as fresh file in same folder.

    I tried to use Concatenate to get the data in single column, and do a Vloop up in file 2. But doing so, if there is 2 rows for same ID, then in vlook up it picks up the first record. Making loop hole in the method.

    Any other possible for to get this done?

    Thanks,
    Keep the Forum clean :


    1. Use [ code ] code tags [ /code ]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    2. Show appreciation to those who have helped you by clicking * Add Reputation below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

  2. #2
    Forum Contributor banaanas's Avatar
    Join Date
    08-26-2014
    Location
    Finland
    MS-Off Ver
    2016
    Posts
    199

    Re: VBA to compare two Files and Delete duplicate

    Should be quite simple with VBA. Please attach both workbooks so we can take a look.
    Tuomas "Banaanas" Savonius
    Trying to give back now when I actually can do some VBA

  3. #3
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    Re: VBA to compare two Files and Delete duplicate

    Thanks for helping out.

    Attached sample file.
    Attached Files Attached Files

  4. #4
    Forum Contributor banaanas's Avatar
    Join Date
    08-26-2014
    Location
    Finland
    MS-Off Ver
    2016
    Posts
    199

    Re: VBA to compare two Files and Delete duplicate

    The two files are not identical. A few follow up questions:

    -What columns are the ones that you wan't to compare? As in what columns need to have the same data in both files for your needs to be considered equal rows?
    -Do you wan't to delete ALL matching rows, or only the first one?
    -Of the files you provided, wich one is the one where the deletion should happen?

  5. #5
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    Re: VBA to compare two Files and Delete duplicate

    Hi Banaanas,

    Thank you for response.

    -What columns are the ones that you wan't to compare? As in what columns need to have the same data in both files for your needs to be considered equal rows?
    >> Last Entry File > Column B, C , D, E , F , G

    Against the File of Last month file in column B, C, J, K, L, M


    -Do you wan't to delete ALL matching rows, or only the first one?

    - All matching row.


    -Of the files you provided, wich one is the one where the deletion should happen?
    - Late Entry file.

    Background : I run a report to publish the leave report for my team on XX days in the morning. But possible that, later in the day team has applied for leave or adjustment has been done. So on the next month when I run the report, I validate to check on the last date if any additional leaves were applied that were not in the original report that I ran in the morning(Last month report)

    Thank you so much for the assistance.

  6. #6
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    Re: VBA to compare two Files and Delete duplicate

    Any luck on getting onto the result sir?
    I am still trying to fiddle by brain to know how to put logic.

  7. #7
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    Re: VBA to compare two Files and Delete duplicate

    If any one came across this post, I solved this with below method.

    1) used concatenate to joing the column in both sheet

    2) used Formula ""=IF(ISERROR(MATCH(RC[-1],'[" & x.Name & "]Sheet1'!C17,0)),"""",RC[-1])"" to find the duplicate in 2nd sheet.

    3) Once duplicate found, removed the record

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Compare two ranges on two different sheets and delete row if duplicate found
    By Metrazal in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-28-2019, 03:04 PM
  2. Find and delete duplicate files if they exist in another specified folder
    By gws1971 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-21-2016, 09:51 AM
  3. [SOLVED] Compare 2 columns and delete duplicate
    By uncleirish in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-15-2013, 11:14 AM
  4. move and delete duplicate files
    By pedroc74 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-16-2011, 01:40 PM
  5. Compare 2 sheets and delete duplicate rows
    By Gavlar in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-26-2011, 01:34 AM
  6. Compare 3 Collums and delete duplicate
    By nackgr in forum Excel General
    Replies: 12
    Last Post: 01-04-2011, 08:27 AM
  7. Compare to Sheets and Delete Duplicate Rows...
    By BossWebmaster in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-24-2008, 11:19 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1