![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Mar 2002
Posts: 33
|
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 |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
Your code ran for me, as-is.
|
|
|
|
|
|
#3 |
|
New Member
Join Date: Mar 2002
Posts: 33
|
I know the code will run as is... it's when I paste it to a command button and run it from there that the problem arises. Am I missing syntax?
|
|
|
|
|
|
#4 |
|
New Member
Join Date: Mar 2002
Posts: 33
|
Anyone?
|
|
|
|
|
|
#5 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
I did paste it into a command button.
|
|
|
|
|
|
#6 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
Try setting the commandbuttons setting
[TakeFocus*******] = False |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|