Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Copy duplicate rows to new sheet

Posted on 2014-03-25
5
Medium Priority
?
3,192 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

718 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