Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

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:



Recommended Productivity Tools for Excel

Kutools for Excel Helps You Always Finish Work Ahead of Time, and Stand Out From Crowd

  • More than 300 powerful advanced features, designed for 1500 work scenarios, increasing productivity by 70%, give you more time to take care of family and enjoy life.
  • No longer need memorizing formulas and VBA codes, give your brain a rest from now on.
  • Become an Excel expert in 3 minutes, Complicated and repeated operations can be done in seconds, 
  • Reduce thousands of keyboard & mouse operations every day, say goodbye to occupational diseases now.
  • 110,000 highly effective people and 300+ world-renowned companies' choice.
  • 60-day full features free trial. 60-day money back guarantees. 2 years of free upgrade and support.

Brings Tabbed Browsing and Editing to Microsoft Office, Far More Powerful Than The Browser's Tabs

  • Office Tab is designed for Word, Excel, PowerPoint and Other Office Applications: 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!
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.

Be the first to comment.