Link to home
Start Free TrialLog in
Avatar of Teo Lo Piparo
Teo Lo Piparo

asked on

Copy duplicate rows with same value in the same column to another sheet

I have a data query where in the first column different values where there are duplicates in bunches and I need to duplicate all the entire rows of those bunch of duplicate.
A1,A2,A3,A4 are the same but the rows of those cells are not. I need to copy all the duplicate rows in a new sheet just inserting the value of A1,A2,A3,A4 in a determined cell.
Could you please help me out?
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Please provide a workbook that contains a sheet that shows what the data looks like and another sheet that shows what you want it to look like.
Hi,

Please try below assuming your data is from Column A1 to D, change accordingly:
Option Explicit

Sub CopyDuplicates()

Dim wstSource As Worksheet, _
    wstOutput As Worksheet
Dim rngMyData As Range, _
    helperRng As Range

Set wstSource = Worksheets("Sheet1")
Set wstOutput = Worksheets("Sheet2")

Application.ScreenUpdating = False

With wstSource
    Set rngMyData = .Range("A1:D" & .Range("A" & .Rows.Count).End(xlUp).Row)
End With
Set helperRng = rngMyData.Offset(, rngMyData.Columns.Count + 1).Resize(, 1)

With helperRng
    .FormulaR1C1 = "=if(countif(C1,RC1)>1,"""",1)"
    .Value = .Value
    .SpecialCells(xlCellTypeBlanks).EntireRow.Copy Destination:=wstOutput.Cells(1, 1)
    .ClearContents
End With

Application.ScreenUpdating = True

End Sub

Open in new window

SOLUTION
Avatar of Shums Faruk
Shums Faruk
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Teo Lo Piparo
Teo Lo Piparo

ASKER

Hi guys,

Here some guidance for what i am looking for.
Here you can see the SQL data query with all the information. In the first column there are the "WEB_QUOTE_NUM" which is the main data.
Those numbers are duplicates sometimes and i would need all those duplicates rows, which can give different information in the other columns.
The other columns are the information that i need to pull to the other sheet with the macro.
User generated imageThis picture instead is showing you the next sheet where i can input the "WEB_QUOTE_NUM" at the top. Going down you will see the column titles. Putting the "WEB_QUOTE_NUM" you will generate all the rows within the same number.
In easy word i need to isolate all the rows of that number in the next sheet just writing down the number requested at the top.
The design might be different but i need to isolate the data.
After this i will create a concatenate formula for generate a comment in the third sheet.
Could be able to help me out with this?
User generated imageHere the Excel file called Teo.xlsx.
Teo.xlsx
Hi Teo
I'm struggling a bit to understand what it is that you want. Have a look at the attached workbook. Do you want the to take the data and have it look like Sheet1 in the attached workbook?
Elmo
Teo.xlsx
Or something like this? Once i have clarity on the end result i can help you with the code
Teo2.xlsx
Yes, is not what i was looking for.
You just translated in rows instead of columns.
I still need to be able to insert the number and receive all the rows of that number in the second sheet.
But thank you.
Teo i think there is a missive communication gap here. I want to know what the data should look like, Your example was VERY BAD. So i'm going to leave now as i see the others have done as well.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Shums proved to be a high reliable resource even when the solution is an abstract idea. Thank you!
You'r Welcome Teo! Glad I was able to help.