Solved

Copy duplicate rows to new sheet

Posted on 2014-03-25
5
3,126 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

This article describes a serious pitfall that can happen when deleting shapes using VBA.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

636 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