[vba] cannot hide/unhide rows when sheet is protected

jpbonono

Board Regular
Joined
Aug 18, 2013
Messages
154
Hi,

I have this code in my module

Code:
Private Sub Boys_Click()If Boys.Value = True Then
Rows("13:57").EntireRow.Hidden = True
Else
 Rows("13:57").EntireRow.Hidden = False
  End If
End Sub

However, my problem is whenever i protect the sheet it doesnt allow me to proceed(debug mode) since i am fully aware that some cells on the rows are protected to.

(I already tried modified the default cell locking(allowing rows) and still wont work)

Are there any work arounds here that would let excel allow the hiding/unhiding feature?

Thank you in advance.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi jpbonono,

im fairly sure if format rows and format columns are ticked when you choose the cell protection rights it should work regardless. If for some reason it still won't work you can add a couple of lines into your macro that will unprotected the sheet, hide / unhide rows, then re-protect the sheet.

i'm currently posting from my iPad but when I get back to my pc I will try and give you some example code to work with
 
Upvote 0
Code:
Private Sub Boys_Click()If Boys.Value = True Then 
ActiveSheet.Unprotect ("[B]password[/B]")
Rows("13:57").EntireRow.Hidden = True 
Else  
Rows("13:57").EntireRow.Hidden = False   
End If 
ActiveSheet.Protect ("[B]password[/B]")
End Sub
Where the bold password can be amended to whatever your password is.
 
Upvote 0
Thank you for a quick reply fishboy, I've already did your suggestion. Your second option however, when I do the unprotecting codes it will also reveal the formulas on some cells that are part of the rows and that will be a big problem.
 
Upvote 0
Thank you for a quick reply fishboy, I've already did your suggestion. Your second option however, when I do the unprotecting codes it will also reveal the formulas on some cells that are part of the rows and that will be a big problem.
The process of unprotecting the sheet, hiding the rows and reprotecting the sheet is pretty much instantaneous. You shouldn't really see your formulas on screen. You can always add this to the start of the macro to prevent screen flicker etc
Application.ScreenUpdating = False
 
Upvote 0

Forum statistics

Threads
1,214,430
Messages
6,119,447
Members
448,898
Latest member
drewmorgan128

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