Stop macro if duplicate record found

  • Hello

    I have created this basic macro to copy data from one worksheet ("Search") to another ("Stocktake") and was wondering if anyone had advice on how to add code to get the macro to check if the values in column D ("Search") are already in column A ("Stocktake).

    If they are the macro would stop and display a message "Asset already counted"


  • This code will copy the data then remove any duplicate rows


    Code
    1. Sub Macro27()
    2. '
    3. ' Macro27 Macro
    4. '
    5. ' Keyboard Shortcut: Ctrl+t
    6. With Sheets("Stocktake")
    7. Range("D10:O17").Copy .Cells(.Rows.Count, 1).End(xlUp).Offset(1)
    8. .Range("A1").CurrentRegion.RemoveDuplicates Columns:=1, Header:=xlYes
    9. End With
    10. End Sub