Excel VBA How to detect if something was pasted in a Worksheet Excel VBA How to detect if something was pasted in a Worksheet vba vba

Excel VBA How to detect if something was pasted in a Worksheet


Private Sub Worksheet_Change(ByVal Target As Range)  Dim UndoList As String  '~~> Get the undo List to capture the last action performed by user  UndoList = Application.CommandBars("Standard").Controls("&Undo").List(1)  '~~> Check if the last action was not a paste nor an autofill  If Left(UndoList, 5) = "Paste" Then    'Do stuff  End IfEnd Sub

This did the trick. For those who need something similar and know the size of their list @MaciejLos' answer would also work.


Worksheet_Change event will do the job if you add a formula into cell which will never be overwritten. Let's say your data are pasted into A1 cell and occupied 5 columns. So, enter below formula into 6. column and row 1.

=COUNTBLANK(A1:A1048576)

Now, you're able to handle/detect paste event ;)