Unable to set the Hidden property of the Range Class

manc

Active Member
Joined
Feb 26, 2010
Messages
340
Dear Demigods,

I am using the following VBA:
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

If Target.Address(0, 0) = "B14" Then
    Cancel = True
    Rows("15:38").Hidden = Not Rows("15:38").Hidden
End If


End Sub

The codes works well until i come to protecting the worksheet.
I leave B14 unLocked (so the code still works), and i also leave some cells within 15:38 unLocked (for example C16, Q16, T37 etc).

When i then protect the worksheet, i get the run-time 1004 error together with
"Unable to set the Hidden property of the Range Class"

Any ideas please?

Best regards
manc
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
You need to unprotect the sheet at the start of the code & reprotect it again at the end.
 
Upvote 0
Thank-you Fluff.
Advice greatly appreciated and problem resolved.

Many thanks
manc
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0
Hi. Been experiencing the same problem. Just new to using excel VBA to i don't know exactly how to protect and unprotect again the sheet.

I tried using -- Sheets("Sheet1").Protect -- but i didn't work. I don't even know where should I put it. Help would be much appreciated. TIA.
 
Upvote 0
Did you include the password in the code if you set one for the sheet?
 
Upvote 0
Did you include the password in the code if you set one for the sheet?
I didnt include any. Anyways, I encountered this error when using a dropdown menu (rows are getting hidden depends on that dropdown value). Instead of the dropdown, i tried using just checkboxes and I think it did good. I'm just gonna settle for this for the meantime. Thanks for your response though.
 
Upvote 0

Forum statistics

Threads
1,213,561
Messages
6,114,316
Members
448,564
Latest member
ED38

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