Solved

Copy duplicate rows to new sheet

Posted on 2014-03-25
5
2,956 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 33

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 33

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

821 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