Hello,
I have searched and found this code to move the macros to another sheet, but I sort of modified it to move to the bottom of the activesheet.
My question is how do I stop so many blank rows from coming between my last row of data and the duplicates?
And more importantly, how do I modify the code to copy both duplicates to the bottom? Right now it is only copying just one.
I usually have files with upwards of 10k rows so other other code on here doesn't seem to work for that many rows and takes a long time with the loops.
Any help would be appreciated.
Thanks
I have searched and found this code to move the macros to another sheet, but I sort of modified it to move to the bottom of the activesheet.
My question is how do I stop so many blank rows from coming between my last row of data and the duplicates?
And more importantly, how do I modify the code to copy both duplicates to the bottom? Right now it is only copying just one.
I usually have files with upwards of 10k rows so other other code on here doesn't seem to work for that many rows and takes a long time with the loops.
Any help would be appreciated.
Thanks
Code:
Sub MoveDupesB()
Dim t As Single
Dim d As Object, x&, xcol As String
Dim lc&, lr&, k(), e As Range
t = Timer
xcol = "B"
lc = Cells.Find("*", after:=[a1], searchdirection:=xlPrevious).Column
lr = Cells.Find("*", after:=[a1], searchdirection:=xlPrevious).Row
ReDim k(1 To lr, 1 To 1)
Set d = CreateObject("scripting.dictionary")
For Each e In Cells(1, xcol).Resize(lr)
If Not d.exists(e.Value) Then
d(e.Value) = 1
k(e.Row, 1) = 1
End If
Next e
If d.Count = lr Then
MsgBox "No duplicates"
Exit Sub
End If
Cells(1, lc + 1).Resize(lr) = k
Range("A1", Cells(lr, lc + 1)).Sort Cells(1, lc + 1), 1
x = Cells(1, lc + 1).End(4).Row
Cells(x + 1, 1).Resize(lr - x, lc).Copy ActiveSheet.Range("A" & lr)
Cells(x + 1, 1).Resize(lr - x, lc).Clear
Cells(1, lc + 1).Resize(x).Clear
MsgBox "Code took " & Format(Timer - t, "0.00 secs")
MsgBox lr & " rows" & vbLf & lc & " columns" & vbLf & _
lr - x & " duplicate rows"
End Sub