can't hide cells using vba when sheet is protected

andrewb90

Well-known Member
Joined
Dec 16, 2009
Messages
1,077
Hello all,

I have a worksheet change event that hides/unhides rows, but when my sheet is protected it doesn't work. now, the sheet is protected in vba uing this:
Code:
    ActiveSheet.Protect "password", _    DrawingObjects:=True, Contents:=True, Scenarios:=True _
        , AllowFormattingCells:=True, AllowFormattingColumns:=True, _
        AllowFormattingRows:=True
    Application.ScreenUpdating = True


My understanding is that "AllowFormattingRows" should allow hiding of rows.

This line of code pops an error: 1004: Unable to set the hidden property of the range class.
Code:
Cells.EntireRow.Hidden = False

any suggestions out there?
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Add Protect's UserfaceOnly:=True option. Then your code can make changes.
 
Upvote 0
I have this:
Code:
    ActiveSheet.Protect "password", DrawingObjects:=True, Contents:=True, Scenarios:=True _
        , AllowFormattingCells:=True, AllowFormattingColumns:=True, UserfaceOnly:=True
and I get a runtime error 1004. Did I not put it in the correct spot?
 
Upvote 0
There is a typo in your text

Code:
ActiveSheet.Protect "password", DrawingObjects:=True, Contents:=True, Scenarios:=True _
        , AllowFormattingCells:=True, AllowFormattingColumns:=True, User[color=red]Inter[/color]faceOnly:=True
 
Upvote 0
Sorry, I misspelled it. UserInterfaceOnly is the parameter's name. Itellisense will show the proper parameter names as you type.

Here are some examples where intellisense works.
Code:
Sub Test()
  Dim ws As Worksheet

  Sheet1.Protect "password", DrawingObjects:=True, Contents:=True, Scenarios:=True _
    , AllowFormattingCells:=True, AllowFormattingColumns:=True, UserinterfaceOnly:=True
    
  Sheet1.Protect "password", True, True, True, True, True, True
  
  Set ws = ActiveSheet
  ws.Protect "password", DrawingObjects:=True, Contents:=True, Scenarios:=True _
    , AllowFormattingCells:=True, AllowFormattingColumns:=True, UserinterfaceOnly:=True
    
  ws.Protect "password", True, True, True, True, True, True
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

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