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 If
End Sub

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

Leave a Comment