Select all duplicates as Range

voycron

New Member
Joined
Apr 5, 2010
Messages
6
Im am new to excel programming, any help will be much appreciated

In column A i have heading "ID_number". Starting from A2 down to A10000 i have a ten digit number, and some(total duplicates my vary) of them are duplicated.
* The current and active sheet is "sheet1"

e.g. Column A
6406982836
6406982836
6406982836
6407027530
6407027530
6407027530
6407027530
6407051169
6407051169
6407051169
6407051169
6407052424
6407052424
6407071319

In the following columns there are, example, addresses. Cells A2,A3,A4 are duplicated but, B2,B3,B4 are not.

I have a simple code that does the following:

once I selected a range anywhere in row2:2 "Sheet1" Then I run a macro:
sub insert()
Rows(ActiveCell.Row).Select
Selection.Copy
Sheets("Sheet2").Select
Rows("2:2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
end sub

Can i compose a code that will example, once i selected B3, run code that will:

Look at columnA and the same row where I've selected a cell, Then select all the cells that are duplicates and Then Select Entire.Rows, Copy, go the "Sheet2" Select row 2:2 and past selection

Please Any Help or Advice...
 

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,046
How about using the 'Autofilter'? If for some reason you'd prefer a macro, here are a couple of questions...

1) When new results are copied and pasted to Sheet2, do you want the old results cleared before pasting the new results, or do you want the new results pasted after the old results?

2) Does Row 1 of Sheet2 contain the corresponding headers from Sheet1?
 

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,194
Code:
Sub Copy_Duplicates()
    
    Application.ScreenUpdating = False
    
    'Clear Sheet2
    With Sheets("Sheet2")
        .Range("A2:A" & .Range("A" & Rows.Count).End(xlUp).Row + 1).EntireRow.ClearContents
    End With
    
    'Copy duplicates
    With Sheets("Sheet1")
        .AutoFilterMode = False
        .Columns("A:A").AutoFilter Field:=1, Criteria1:=.Range("A" & ActiveCell.Row).Text
        .Cells.SpecialCells(xlCellTypeVisible).EntireRow.Copy _
            Destination:=Sheets("Sheet2").Range("A1")
        .AutoFilterMode = False
    End With
    
    Application.ScreenUpdating = True
    
End Sub
 

voycron

New Member
Joined
Apr 5, 2010
Messages
6
Thank you AlphaFrog,

The code works Perfect!!!!

Thanks a Million

Cheers
Edwin
 

Forum statistics

Threads
1,085,564
Messages
5,384,465
Members
401,902
Latest member
lilytran14

Some videos you may like

This Week's Hot Topics

Top