nniedzielski
Well-known Member
- Joined
- Jan 8, 2016
- Messages
- 598
- Office Version
- 2019
- Platform
- Windows
I am running this block of code to find duplicate numbers on two different worksheets, then copying the duplicates from one of the sheets and pasting it to another worksheet called Dup.
This takes an inordinate amount of time to run and often freezes and locks up, once the code has run also the worksheets stay unresponsive, like when i click on a cell it might take 6 or 7 seconds for excel to actually select the cell, its weird.
Is there a better way to run through worksheets to find duplicates? I did this code by using the recorder, and getting some help in here to clean it up:
This takes an inordinate amount of time to run and often freezes and locks up, once the code has run also the worksheets stay unresponsive, like when i click on a cell it might take 6 or 7 seconds for excel to actually select the cell, its weird.
Is there a better way to run through worksheets to find duplicates? I did this code by using the recorder, and getting some help in here to clean it up:
VBA Code:
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
Dim exp As Worksheet
Dim yc As Worksheet
Set exp = Sheets("Export")
Set yc = Sheets("Yard")
With exp.Columns("B:B")
.FormatConditions.AddUniqueValues
.FormatConditions(1).DupeUnique = xlDuplicate
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
End With
.FormatConditions(1).StopIfTrue = False
End With
With yc.Columns("A:A")
.FormatConditions.AddUniqueValues
.FormatConditions(1).DupeUnique = xlDuplicate
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
End With
.FormatConditions(1).StopIfTrue = False
End With
With yc
.Range("A1:F1").AutoFilter Field:=1, Criteria1:=RGB(255, _
255, 0), Operator:=xlFilterCellColor
.AutoFilter.Range.Copy Sheets("Dup").Range("A1")
.AutoFilter.Range.Offset(1).EntireRow.Delete
.Range("A1:F1").AutoFilter
End With
With Sheets("Dup").Range("A1:F1")
.Font.Bold = True
End With
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True