
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Move Duplicate Rows to Another Sheet in Excel
Your worksheets could become clogged with duplicate data, making it challenging to organise and examine your data effectively. This video will walk you through a step-by-step procedure for locating duplicate rows and relocating them to another sheet in order to keep your spreadsheet tidy and organised.
We'll look at methods for completing this task that take advantage of Excel's pre-built features and functionalities. No matter what degree of Excel proficiency you possess, this class will provide you the knowledge and abilities to successfully handle duplicate data and streamline your workflow..
Move Duplicate Rows to Another Sheet
Here we will first create a VBA module, then select the cell to complete the task. So let us see a simple process to learn how you can move duplicate rows to another sheet in Excel.
Step 1
Consider an Excel sheet where you have duplicate rows in the sheet, similar to the below image.
First, right-click on the sheet name and select View Code to open the VBA application.
Right Click > View Code.
Step 2
Then click on Insert and select Module, then copy the below code into the text box.
Insert > Module > Copy.
Code
Sub CutDuplicates() 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:", "Move Duplicate Rows", Selection.Address, , , , , 8) If xRgS Is Nothing Then Exit Sub Set xRgD = Application.InputBox("Please select a desitination cell:", "Move Duplicate Rows", , , , , , 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
Step 3
Then click F5 to run the code. Then select a column and click OK.
Step 4
Finally, select a single cell to paste the data into, then click OK.
This is how you can move duplicate rows to another sheet in Excel.
Note
If you want to move rows based on rows, use the below code.
Code
Sub CutDuplicates() 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:", "Move Duplicate Rows", Selection.Address, , , , , 8) If xRgS Is Nothing Then Exit Sub Set xRgD = Application.InputBox("Please select a desitination cell:", " Move Duplicate Rows", , , , , , 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
Conclusion
In this tutorial, we have used a simple example to demonstrate how you can move duplicate rows to another sheet in Excel to highlight a particular set of data.