Range Error

CW-NEN

Board Regular
Joined
Jul 18, 2007
Messages
55
I have been using this code in a macro for a while. Today I switched it to a command button. Now I get this error:

"Run time error '1004'
Select Method of Range class failed"

Please Help.



Code:
Private Sub CommandButton4_Click()
'   Add City
    Sheets("Budget Price").Select
    ActiveSheet.Unprotect Password:="password"
-->  Range("A21").Select
    Selection.EntireRow.Insert
    Sheets("City List").Select
    Selection.Copy
    Sheets("Budget Price").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    ActiveSheet.Protect DrawingObjects:=True, contents:=True, Scenarios:=True, Password:="password"

End Sub

Thanks
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Did you try putting

Code:
ActiveSheet.

In front of it. Better still reference the sheet or use With.

HTH


Dave
 
Upvote 0
This is a bit cleaner

Code:
Private Sub CommandButton4_Click()
'   Add City
    Sheets("Budget Price").Select
    ActiveSheet.Unprotect "password"
    ActiveSheet.Range("A21").EntireRow.Insert
    Sheets("City List").Copy
    Sheets("Budget Price").PasteSpecial
    Application.CutCopyMode = False
    ActiveSheet.Protect "password"

End Sub
 
Upvote 0
I'm glad it works for you.

All the very best

Dave
 
Upvote 0

Forum statistics

Threads
1,214,429
Messages
6,119,435
Members
448,898
Latest member
dukenia71

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top