Backup your data.
Place code in a standard module.
Select rows to be copied.
Run: CopyBCE2Sheet2ABC
Function DoesRowAlreadyExistInSheet2(vColA As Variant, vColB As Variant, vColC As Variant) As Boolean
Dim rg As Range, rgCell As Range, sAddress As String
With Worksheets(2)
Set rg = .Range("A:A")
Set rgCell = rg.Find(What:=vColA, _
LookIn:=xlValues, _
Lookat:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=True)
If Not rgCell Is Nothing Then
sAddress = rgCell.Address
Do
If .Cells(rgCell.Row, "B") = vColB _
And .Cells(rgCell.Row, "C") = vColC Then
DoesRowAlreadyExistInSheet2 = True
Exit Function
End If
Set rgCell = rg.FindNext(rgCell)
Loop While Not rgCell Is Nothing And sAddress <> rgCell.Address
End If
End With
End Function
Sub CopyBCE2Sheet2ABC()
Dim ws2 As Worksheet, nTop As Long, nBottom As Long, nRow As Long, nNextRow As Long
nTop = Selection.Row
nBottom = Selection.Rows.Count + Selection.Row - 1
Set ws2 = Worksheets(2)
If ActiveSheet.Name = ws2.Name Then Exit Sub
With ws2
nNextRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
End With
For nRow = nTop To nBottom
If Not DoesRowAlreadyExistInSheet2(Cells(nRow, "B"), Cells(nRow, "C"), Cells(nRow, "E")) Then
ws2.Cells(nNextRow, "A") = Cells(nRow, "B")
ws2.Cells(nNextRow, "B") = Cells(nRow, "C")
ws2.Cells(nNextRow, "C") = Cells(nRow, "E")
nNextRow = nNextRow + 1
End If
Next nRow
End Sub
Bookmarks