I currently have a code written to find duplicate values starting in range "A3" to last row used; highlight duplicates red, both the first and last instance; Filter by color highlighted and finally sort smallest to largest.
I will be using these duplicates later to copy to another sheet. The data starts in column "A3" to "V3" and to last row used. Data will range anywhere from 10,000 to 40,000 rows, maybe more depending on the data received.
My problem is this marco runs very slow and at times will freeze up.. Is there another way to achieve the same result but more efficiently and quicker?
Sub filtersort ()
Dim sht As Worksheet
Set sht = Worksheets("Sheet1")
Lastrow = Range("A" & Rows.Count).End(xlUp).Row
N = Cells(Rows.Count, "A").End(xlUp).Row
sht.Range("A3:A" & Lastrow).Select
Selection.FormatConditions.AddUniqueValues
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
Selection.FormatConditions(1).DupeUnique = xlDuplicate
With Selection.FormatConditions(1).Font
.Color = -16383844
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13551615
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
sht.Range("A3:A" & Lastrow).Select
Application.CutCopyMode = False
Selection.AutoFilter
ActiveSheet.Range("$A$3:$A$" & Lastrow).AutoFilter Field:=1, Criteria1:=RGB(255, _
199, 206), Operator:=xlFilterCellColor
sht.Range("A3:V" & N).Sort Key1:=Range("A1"), Order1:=xlDescending, Header:=xlYes
End Sub