LT_Orange
LT_Orange

Reputation: 53

VBA Remove Duplicates Row based on two Column Macro

I have over 200k records of customer data in my csv file. I want to be able to create a macro that will compare Account # and product name. Since Account # is a primay key it can only be tied to single product name.

I want my macro to give the similar output. Right now when i run my macro on over 200k records. I get only 20 rows.

enter image description here

Sub DelDupl()
Dim Rng As Range, Dn As Range, Del As Integer, Msg As Integer
Set Rng = Range(Range("C2"), Range("C" & Rows.Count).End(xlUp))
For Msg = 1 To 2
    For Del = Rng.Count To 1 Step -1
        If Msg = 1 And Application.CountIf(Rng, Cells(Del, "C")) = 1 Then

        End If
        If Msg = 2 And Application.CountIf(Rng, Cells(Del, "C")) > 1 Then
            Rows(Del).EntireRow.Delete
        End If
    Next Del
Next Msg
End Sub

Thanks in advance!

Upvotes: 0

Views: 11638

Answers (1)

user6432984
user6432984

Reputation:

MSDN - Range.RemoveDuplicates Method (Excel): Removes duplicate values from a range of values.

enter image description here

Sub DelDupl()

    Range("A1").CurrentRegion.RemoveDuplicates Columns:=Array(3, 4), Header:=xlYes

End Sub

Upvotes: 3

Related Questions