VBA to CUT and paste to a different sheet

abrig005

Board Regular
Joined
Jan 6, 2017
Messages
82
Office Version
  1. 365
Platform
  1. Windows
I'm trying to figure out how to cut and paste ONLY duplicate names in Column A to a new sheet.

In the attached Excel example, the highlighted rows in Sheet 1 have duplicates in Column A.

Sheet 2 shows just the duplicate values COPIED from Sheet 1.

Note: I left the highlighted rows in Sheet 1 to show the example, but they should not be there after the VBA code is run.
1667828802227.png
1667828815072.png
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
try this on a COPY of your file.
VBA Code:
Sub Move_Them()

Dim rs As Worksheet
Set rs = Worksheets("Sheet2")
l_Row = Cells(Rows.Count, "A").End(xlUp).Row
For r = 2 To l_Row

If WorksheetFunction.CountIf(Range("A:A"), Cells(r, "A")) > 1 Then
    lr = rs.Cells(Rows.Count, "A").End(xlUp).Row + 1
    Rows(r).Copy Destination:=rs.Rows(lr)
    Cells(r, "B") = "DELETE"
End If

Next r

'delete old records
On Error Resume Next
    With Range("B2:B" & l_Row)
        .Replace "DELETE", False, xlWhole
        .SpecialCells(xlCellTypeConstants, 4).EntireRow.Delete
    End With
On Error GoTo 0

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,810
Messages
6,121,690
Members
449,048
Latest member
81jamesacct

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