+ Reply to Thread
Results 1 to 5 of 5

Delete matching records but some duplicated.

  1. #1
    Forum Contributor
    Join Date
    08-02-2005
    Location
    LONDON
    MS-Off Ver
    OFFICE365
    Posts
    167

    Delete matching records but some duplicated.

    Hi

    I dont know where to start on this one.

    I have a workbook with 2 sheets and data in columns A-D.What im trying to do is when there is a match exactly the same on both sheets I need the row deleting from sheets 1 & 2. The issue I have is that sometimes there is 1 row of data on sheet 1 and 2 or 3 rows with the same data in sheet 2 and I dont need both rows of data deleting in sheet 2 and only 1 as there is only 1 entry on sheet 1.

    The data will always be in columns A-D but spread over different rows over the worksheet. I.E lets say sheet 1 row 99 matches data in sheet 3 row 400 then I need both rows deleting.

    Is there anyway I can do this
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Delete matching records but some duplicated.

    Hi tweacle,

    Try this (initially on a copy of your data as the results cannot be undone if they're not as expected):

    Please Login or Register  to view this content.
    After I ran the code only 45631 in Sheet2 remained. Note the data for both sheets is only across columns A to C not A to D as you say?

    Thanks,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  3. #3
    Forum Contributor
    Join Date
    08-02-2005
    Location
    LONDON
    MS-Off Ver
    OFFICE365
    Posts
    167

    Re: Delete matching records but some duplicated.

    Thanks but it dont seem to be working unless its me.


    In the enclosed workbook Im using (attached) on sheet 2 there is more value than whats on sheet 1.

    What you would think that sheet 2 has duplicated data of which is one reason why but also there could be data in sheet 2 that is not in sheet 1 causing the difference too.
    There are occasions that sometimes there are duplicated entries on sheet 2 but they are not duplicated as there are 2 entries on sheet 1 too

    Im trying to get a macro that leaves all the entries that are on sheet 2 as duplicated or not on sheet 1 listed.

    I have posted this on here too

    https://www.mrexcel.com/board/thread...1135692/page-3
    Attached Files Attached Files
    Last edited by tweacle; 07-08-2020 at 04:02 PM. Reason: editedexcelbook

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi, try this demonstration !


    According to your last attachment - original is too poor - as a VBA beginner starter :

    PHP Code: 
    Sub Demo1()
      Const 
    5"A2:A#&""¤""&B2:B#&""¤""&C2:C#&""¤""&D2:D#"
        
    Dim R&, V(1 To 2), W(1 To 2), X
        
    For 1 To 2
            V
    (R) = Sheets(R).Evaluate(Replace(F"#"Sheets(R).[A2].End(xlDown).Row))
            
    W(R) = Evaluate("{0" Application.Rept(";0"UBound(V(R)) - 1) & "}")
        
    Next
        
    For 1 To UBound(V(1))
            
    Application.Match(V(1)(R1), V(2), 0)
            If 
    IsNumeric(XThen W(1)(R1) = 1W(2)(X1) = 1V(2)(X1) = Empty
        
    Next
           X 
    Application.Sum(W(1))
        If 
    X Then
                Application
    .ScreenUpdating False
            
    For 1 To 2
                With Sheets
    (R).[A2].CurrentRegion.Rows
                    
    .Columns(C) = W(R)
                    .
    Resize(, C).Sort .Columns(C), xlAscendingHeader:=xlNo
                     Union
    (.Item(.Count ":" & .Count), .Columns(C)).Clear
                End With
            Next
                Application
    .ScreenUpdating True
        End 
    If
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !

  5. #5
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Delete matching records but some duplicated.

    This is a lot different...

    I have a workbook with 2 sheets and data in columns A-D.What im trying to do is when there is a match exactly the same on both sheets I need the row deleting from sheets 1 & 2
    ...from this:

    Im trying to get a macro that leaves all the entries that are on sheet 2 as duplicated or not on sheet 1 listed


    That said try this (again on a copy of your data as the results cannot be undone if they're not as expected):

    Please Login or Register  to view this content.

+ 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] How do I look for missing /duplicated data and delete matching data.
    By tweacle in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-08-2020, 03:22 PM
  2. [SOLVED] Combining semi-duplicated records (with different columns)?
    By efjim in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-16-2016, 03:54 PM
  3. Adding Search Function To Delete Matching Records
    By sweetrevelation in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-01-2009, 09:20 AM
  4. viewing duplicated records
    By brain_chilled in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-30-2008, 04:53 PM
  5. [SOLVED] How do you use filter to view duplicated records in Excel?
    By Sharon in forum Excel General
    Replies: 2
    Last Post: 01-09-2006, 09:30 AM
  6. How to delete duplicated records. Each record has four lines
    By Arcesio Hernandez in forum Excel General
    Replies: 2
    Last Post: 07-26-2005, 07:05 PM
  7. [SOLVED] Remove ALL duplicated records, leaving behind NONE
    By Christopher Dawes in forum Excel General
    Replies: 2
    Last Post: 06-06-2005, 07:05 PM

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