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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
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

Forum statistics

Threads
1,223,627
Messages
6,173,425
Members
452,515
Latest member
Alicedonald9

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