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...
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
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?
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,873
Members
449,056
Latest member
ruhulaminappu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top