I recorded this macro and made a few minor modifications. When I run it from the "run macro" option, it works like a charm. However, when I paste this code into a commad button, clickling the button gives me a Run Time 1004 (Select method of Range class failed). This code is assuming the user has an entire row selected. Any help or advice?
Private Sub CommandButton1_Click()
Dim ans As String
Application.ScreenUpdating = False
ans = MsgBox("Are you sure you want to delete this employee?", vbYesNo, "Confirm Employee Deletion")
If ans = vbYes Then
Selection.Cut
Sheets("Deleted Employees").Select
Rows("2:2").Select
Selection.Insert Shift:=xlDown
Range("I2").Select
ActiveCell.Value = Format(Now, "mm/dd/yy")
Sheets("Current Employees").Select
Selection.Delete Shift:=xlUp
Else
End If
End Sub
Private Sub CommandButton1_Click()
Dim ans As String
Application.ScreenUpdating = False
ans = MsgBox("Are you sure you want to delete this employee?", vbYesNo, "Confirm Employee Deletion")
If ans = vbYes Then
Selection.Cut
Sheets("Deleted Employees").Select
Rows("2:2").Select
Selection.Insert Shift:=xlDown
Range("I2").Select
ActiveCell.Value = Format(Now, "mm/dd/yy")
Sheets("Current Employees").Select
Selection.Delete Shift:=xlUp
Else
End If
End Sub