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,005
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,166
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,081,767
Messages
5,361,164
Members
400,617
Latest member
barron1

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top