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

    Sub Macro27()
    ' Macro27 Macro
    ' Keyboard Shortcut: Ctrl+t
    With Sheets("Stocktake")
    Range("D10:O17").Copy .Cells(.Rows.Count, 1).End(xlUp).Offset(1)
    .Range("A1").CurrentRegion.RemoveDuplicates Columns:=1, Header:=xlYes
    End With
    End Sub

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!