Another "finding duplicates" macro

jlang11

New Member
Joined
Aug 9, 2018
Messages
5
Office Version
  1. 365
Platform
  1. Windows
I seem to have lost my log in info and the site doesnt recognize my email address so a new account it is. I have a spreadsheet that has 14 columns and 50k+ rows, but I need to search for duplicates in 2 of the columns... but not just duplicates.... here is some sample data. One of the columns has a business name, and another has invoice numbers. I need to pick out the duplicate invoice numbers from the same vendor. I'm not particular if it highlights the duplicates in 1 row, both rows, adds a word in column 15 "Duplicate" or how it notes that its a dup. I already have a some code sorting and deleting rows before this code would come into play, and will most likely add more code to sort bringing the dups to the top.

I thought about maybe a nested if statement in column 15, sorted by vendor, then invoice number, something like if A2 = A3 AND B2 = B3, 1,0, but Id like to just add to the macro so its one smooth processes instead of running one macro, manually adding an IF statement, then running another macro.

Any help is greatly appreciated!



Walmart114
Walmart852
Kmart444
Kmart5721
ABC LiquorP874103
ABC Liquor54984
Walmart2574
Walmart741
Kmart88
Kmart4555
ABC Liquor28407
ABC LiquorT456
Kmart8730
KmartF987
Walmart258
Walmart114
ABC Liquor54846
Kmart2013
Walmart289
Kmart147
Walmart963
ABC Liquor221874
ABC Liquor28407
Walmart654
Kmart2471
Walmart369
ABC LiquorR5874
ABC Liquor56478

<colgroup><col><col></colgroup><tbody>
</tbody>
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Try this one...

Code:
Sub Duplicates()


Dim LastRow As Long
LastRow = ActiveSheet.Range("A1").CurrentRegion.Rows.Count
    Cells.Select
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("A2:A" & LastRow) _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("B2:B" & LastRow) _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Sheet1").Sort
        .SetRange Range("A1:O" & LastRow)
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With


Dim Cell As Variant


For Each Cell In Range("A2:A" & LastRow)


Dim rng As Range
Set rng = Range(Cell, Cell.Offset(1, 0))


If Application.WorksheetFunction.CountIf(Range("A2:A" & LastRow), Cell) > 1 Then
    If Cell.Offset(0, 1).Value = Cell.Offset(1, 1).Value Then
    rng.EntireRow.Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 65535
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    End If
    End If
Next


End Sub

MickG was able to help me a lot with some complex duplication matches which you can find here... This may or may not be helpful. He offered some awesome help! https://www.mrexcel.com/forum/excel-questions/1065716-highlight-rows-based-sum-multiple-cells.html
 
Upvote 0

Forum statistics

Threads
1,215,034
Messages
6,122,782
Members
449,095
Latest member
m_smith_solihull

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