Solved

Copy duplicate rows to new sheet

Posted on 2014-03-25
5
2,881 Views
Last Modified: 2014-03-26
Could an expert provide me with VBA to move duplicates please.

I have a spreadsheet that has a header row in row 1

columns go from A to T

Number of rows will change

I need to look in column H for any duplicates and wherever I find one I need to move all of the items [complete row] to a new worksheet. [Named Duplicates] I also need the header row from Sheet1 copied onto the sheet named Duplicates.

So, if in Cell H3 I find abcdef and abcdef is also in H4 I need to move both rows to the sheet named duplicates

if in Cell H3 I find abcdef and abcdef is also in H4 and H5 and H6 I need to move all rows to the sheet named duplicates

Many thanks
0
Comment
Question by:Jagwarman
  • 2
  • 2
5 Comments
 
LVL 39

Accepted Solution

by:
nutsch earned 500 total points
ID: 39953775
Here it is:

Sub MoveDups()
Dim lLastRow As Long, lRowLoop As Long

lLastRow = Cells(Rows.Count, 1).End(xlUp).Row

Range("u2:u" & lLastRow).FormulaR1C1 = "=countif(R2C8:R" & lLastRow & "C8,RC8)"
Range("u2:u" & lLastRow).NumberFormat = "0"

With Range("A1:u" & lLastRow)
    .AutoFilter
    .AutoFilter field:=21, Criteria1:=">1"
    .Resize(, 20).SpecialCells(xlCellTypeVisible).Copy Sheets("Duplicates").Cells(1, 1)
    .Offset(1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    .AutoFilter
End With

Columns("U").Delete

End Sub

Open in new window

0
 
LVL 32

Expert Comment

by:Rob Henson
ID: 39955708
Have we not seen this same question before, just recently???

Other option would be to use Advanced Filter function to separate unique values to their own sheet.

Thanks
Rob H
0
 
LVL 32

Expert Comment

by:Rob Henson
ID: 39955711
0
 

Author Comment

by:Jagwarman
ID: 39955723
The previous question was only to move one of the duplicates this is to move all items where there is a duplicate

so similar but different
0
 

Author Closing Comment

by:Jagwarman
ID: 39955727
Exactly what I wanted
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question