Macro issues when I protect my worksheet

ExcelNovice

Well-known Member
Joined
May 12, 2002
Messages
583
I'm using the code below, but keep getting the following error:
Run-time error '1004'

Private Sub CommandButton31_Click()

ActiveSheet.Unprotect Password:="password1"

Range("AA57:AA57").Select
Range("AA57:AA57").Activate
Selection.RowHeight = 12.75
Range("AA58:AA58").Select
Range("AA58:AA58").Activate
Selection.RowHeight = 12.75
Range("AA59:AA59").Select
Range("AA59:AA59").Activate
Selection.RowHeight = 13.5

ActiveSheet.Protect Password:="password1"

End sub

Any idea on what I'm doing wrong and how to correct the problem?
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Does this work?
Code:
Private Sub CommandButton31_Click()

    With ActiveSheet
        .Unprotect Password:="password1"
        .Range("AA57:AA57").RowHeight = 12.75
        .Range("AA58:AA58").RowHeight = 12.75
        .Range("AA59:AA59").RowHeight = 13.5
        .Protect Password:="password1"
    End With

End Sub
 
Upvote 0
Maybe the password is incorrect, try and manually unprotect the sheet with password1
 
Upvote 0

Forum statistics

Threads
1,217,364
Messages
6,136,112
Members
449,993
Latest member
Sphere2215

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