Stephen_IV
Well-known Member
- Joined
- Mar 17, 2003
- Messages
- 1,180
- Office Version
- 365
- 2019
- Platform
- Windows
Good afternoon,
I have code below that copies duplicates to sheet2. The code works find but is slow. Does anyone have any other way or code that is faster? Thanks in advance! With over 100,000 rows it is slow!
I have code below that copies duplicates to sheet2. The code works find but is slow. Does anyone have any other way or code that is faster? Thanks in advance! With over 100,000 rows it is slow!
Code:
Sub Dupe()
Sub Dupe()
Dim sh1 As Worksheet
Dim sh2 As Worksheet
Set sh1 = Sheets(1)
Set sh2 = Sheets(2)
Dim lastRow As Long
Dim i As Long
Dim addrow As Long
lastRow = sh1.Cells(Rows.Count, "A").End(xlUp).Row
addrow = sh2.Cells(Rows.Count, "A").End(xlUp).Row + 1
Set r = Range("a1:a" & lastRow)
For Each mcell In r
If WorksheetFunction.CountIf(r, mcell) > 1 Then
mcell.Copy sh2.Range("A" & addrow)
mcell.Offset(0, 1).Copy sh2.Range("B" & addrow)
addrow = addrow + 1
End If
Next mcell
End Sub