Unable to set the Hidden property of the Range Class

manc

Active Member
Joined
Feb 26, 2010
Messages
335
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

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
62,473
Office Version
  1. 365
Platform
  1. Windows
You need to unprotect the sheet at the start of the code & reprotect it again at the end.
 

manc

Active Member
Joined
Feb 26, 2010
Messages
335
Thank-you Fluff.
Advice greatly appreciated and problem resolved.

Many thanks
manc
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
62,473
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback
 

robertjude

New Member
Joined
Dec 5, 2019
Messages
8
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

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.
 

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
14,194
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
Did you include the password in the code if you set one for the sheet?
 

robertjude

New Member
Joined
Dec 5, 2019
Messages
8
Office Version
  1. 365
Platform
  1. Windows
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.
 

Forum statistics

Threads
1,141,492
Messages
5,706,671
Members
421,462
Latest member
Eame20

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
Top