I am trying to write a macro that will move all duplicate rows based on column 3 into another sheet. For example:
Column 3
xyz
qwe
abc def
abc def gh
The last 2 rows are to be considered as duplicate and need to be deleted from this sheet and moved to another. My knowledge in macro scripting is very basic so please be detailed. Following is what i have so far:
Column 3
xyz
qwe
abc def
abc def gh
The last 2 rows are to be considered as duplicate and need to be deleted from this sheet and moved to another. My knowledge in macro scripting is very basic so please be detailed. Following is what i have so far:
Code:
Sub deleteDups()
Dim i As Integer
Dim colToMatch As Integer
Dim wb As Workbook
Dim dupsWs As Worksheet
Dim ws As Worksheet
Const dupsWsName = "Duplicate Rows"
Set wb = ActiveWorkbook
Set ws = wb.Worksheets(2)
Application.DisplayAlerts = False
'clean up, may exist if second run
If sheetExists(dupsWsName) Then
wb.Worksheets(dupsWsName).Delete
End If
'recreate
wb.Worksheets.Add Before:=wb.Worksheets(1)
Set dupsWs = ActiveSheet
dupsWs.Name = dupsWsName
i = 1 'Change this to 0 if no header
colToMatch = 3 'no. of the column to match
MsgBox ws.Name
MsgBox dupsWs.Name
'## Copy the header from the original to the new
'## Loop through the original sheet and move the duplicate entries (i.e both the rows)
MsgBox "All done ..."
End Sub</pre>