How to move duplicate rows to another sheet in Excel?
If you have a list of data range which contains some duplicate values in a specific column, now, you want to move the entire rows to another sheet based on the duplicate cells. How could you deal with this task in Excel?
Move entire rows to another sheet based on duplicate cells in a column
Move entire rows to another sheet based on duplicate rows
Move entire rows to another sheet based on duplicate cells in a column
If there are duplicate values in a column, then move the entire rows to another sheet, the following VBA code can do you a favor:
1. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.
2. Click Insert > Module, and paste the following code in the Module window.
VBA code: Move entire rows to another sheet based on duplicate cells in a column:
Sub CutDuplicates()
'Updateby Extendoffice
Dim xRgS As Range
Dim xRgD As Range
Dim I As Long, J As Long
On Error Resume Next
Set xRgS = Application.InputBox("Please select the column:", "KuTools For Excel", Selection.Address, , , , , 8)
If xRgS Is Nothing Then Exit Sub
Set xRgD = Application.InputBox("Please select a desitination cell:", "KuTools For Excel", , , , , , 8)
If xRgD Is Nothing Then Exit Sub
xRows = xRgS.Rows.Count
J = 0
For I = xRows To 1 Step -1
If Application.WorksheetFunction.CountIf(xRgS, xRgS(I)) > 1 Then
xRgS(I).EntireRow.Copy xRgD.Offset(J, 0)
xRgS(I).EntireRow.Delete
J = J + 1
End If
Next
End Sub
3. Then press F5 key to run this code, and in the popped out dialog box, select the column which contains the duplicate cells you want to move based on, see screenshot:
4. Then click OK, in another prompt box, please select a cell in another sheet where you want to put the moved rows, see screenshot:
5. And then click OK, the rows which have duplicate values in column A have been moved into a new sheet, see screenshot:
Move entire rows to another sheet based on duplicate rows
If you want to move the duplicate rows from a range of cells, the following VBA code can help you:
1. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.
2. Click Insert > Module, and paste the following code in the Module window.
VBA code: Move entire rows to another sheet based on duplicate rows:
Sub CutDuplicates()
'Updateby Extendoffice
Dim xRgD As Range, xRgS As Range
Dim I As Long, J As Long, K As Long, KK As Long
On Error Resume Next
Set xRgS = Application.InputBox("Please select the data range:", "KuTools For Excel", Selection.Address, , , , , 8)
If xRgS Is Nothing Then Exit Sub
Set xRgD = Application.InputBox("Please select a desitination cell:", "KuTools For Excel", , , , , , 8)
If xRgD Is Nothing Then Exit Sub
KK = 0
For I = xRgS.Rows.Count To 1 Step -1
For J = 1 To I - 1
For K = 1 To xRgS.Columns.Count
Debug.Print xRgS.Rows(I).Cells(, K).Value
Debug.Print xRgS.Rows(J).Cells(, K).Value
If xRgS.Rows(I).Cells(, K).Value <> xRgS.Rows(J).Cells(, K).Value Then Exit For
Next
If K = xRgS.Columns.Count + 1 Then
xRgS.Rows(I).EntireRow.Copy xRgD.Offset(KK, 0).EntireRow
xRgS.Rows(I).EntireRow.Delete
KK = KK + 1
End If
Next
Next
End Sub
3. Then press F5 key to run this code, in the popped out dialog box, select the select the data range that you want to move the duplicate rows, see screenshot:
4. Click OK button, and then in another prompt box, select a cell in a new sheet where you want to put the moved supplicate rows, see screenshot:
5. Then click OK button, and now, the duplicate rows have been moved into another sheet you specified at once, see screenshot:
Best Office Productivity Tools
Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time. Click Here to Get The Feature You Need The Most...
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!






