Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 04-23-2018, 01:17 PM
Carchee Carchee is offline Compare two lists and delete rows that are NOT the same Windows 10 Compare two lists and delete rows that are NOT the same Office 2013
Advanced Beginner
Compare two lists and delete rows that are NOT the same
 
Join Date: Dec 2013
Posts: 46
Carchee is on a distinguished road
Default Compare two lists and delete rows that are NOT the same


I pulled this code from a youtube video and it compares two lists and removes duplicates from one of them. However I would like to change the code so it removes non-duplicates. Here is the code:

Code:
Sub RemoveDupsBetweenLists()
Dim sht1 As Worksheet
Dim sht2 As Worksheet
Dim C1row As Long
Dim C2row As Long
Dim C2TotalRows As Long
Dim CustID As String
Dim NoDups As Long
Set sht1 = Worksheets("Customers 1")
Set sht2 = Worksheets("Customers 2")
sht2.Activate
C2TotalRows = Application.CountA(Range("A:A"))
C1row = 2
Do While sht1.Cells(C1row, 2).Value <> ""
CustID = sht1.Cells(C1row, 2).Value
    For C2row = 2 To C2TotalRows
        If CustID = Cells(C2row, 2).Value Then
 
            sht1.Activate
            Rows(C1row).Delete
            NoDups = NoDups + 1
            C1row = C1row - 1
            sht2.Activate
            Exit For
 
        End If
 
    Next
 
    C1row = C1row + 1
Loop
 
MsgBox NoDups & " Duplicates were removed"
End Sub
Now what I think I need to do is just change the code from
Code:
 If CustID = Cells(C2row, 2).Value Then
to
Code:
 If CustID <> Cells(C2row, 2).Value Then
However when I change the = to <>, it deletes all the rows instead of just those that don't match. Can anyone critique this code
Reply With Quote
 

Tags
compare documents, delete duplicates



Similar Threads
Thread Thread Starter Forum Replies Last Post
delete custom lists macro ewso Excel Programming 13 10-12-2017 07:39 AM
Compare two lists and delete rows that are NOT the same frustrating beyond belief!: trying to compare two lists of URLs cachaco Excel 2 08-25-2015 08:10 AM
Compare two lists and delete rows that are NOT the same Delete blank rows between the two rows that contain data beginner Excel Programming 5 12-26-2014 12:29 AM
Compare two lists and delete rows that are NOT the same Delete All empty Rows - Print - Undo all Rows deleted Bathroth Word VBA 1 10-01-2014 01:40 PM
Conditional Formatting to compare lists and order SarahBear Excel 4 07-09-2014 09:40 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:17 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft