You can also block all user interactions in the userform by setting its Enabled to False and using GetAsyncKeyState to check if the Esc key is pressed to cancel the operation.
Code:
Private Declare PtrSafe Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub CommandButton2_Click()
Dim i As Long, t As Single
t = Timer
Application.ScreenUpdating = False
Enabled = False
For i = 1 To 500000
' random task
Cells(i, "A").Value = Cells(i, "A").Value + Cells(i, "B").Value
'update status
If (Timer - t) > 0.1 Then
Caption = (i * 100 \ 500000) + 1 'displays progress
DoEvents
If GetAsyncKeyState(27) < 0 Then
If MsgBox("Do you want cancel the operation ?", vbYesNo Or vbExclamation) = vbYes Then
Exit For
End If
End If
t = Timer
End If
Next
Application.ScreenUpdating = True
Unload Me
End Sub