Hiding Sheets if I have a Worksheet Selection Change

rhombus4

Active Member
Joined
May 26, 2010
Messages
497
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi

I can hide the rows I want by using
VBA Code:
Rows("23:35").EntireRow.Hidden = True or Rows("23:35").Hidden = True

However I have a worksheet selection change which does some stuff when selecting rows 10 to 100 and I get an error
run time error 1004 - Unable to set the Hidden property of the Range class

I tried turning off application.enableevents but still same error
VBA Code:
Application.EnableEvents = False
  Rows("23:35").EntireRow.Hidden = True
Application.EnableEvents = True
 

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.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
62,466
Office Version
  1. 365
Platform
  1. Windows
Is the sheet protected?
 

rhombus4

Active Member
Joined
May 26, 2010
Messages
497
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
it was but the code unprotected it before it unhid the Rows.

Just realised however the worksheet change event unprotected and protected the sheet so I've just added another line before the unhide which seems to have done the trick

Maybe I should have added the code to the worksheet change when it was unprotected if a certain cell contained a certain value. instead i added it to the sub in question although don't think it would have made much of a difference
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
62,466
Office Version
  1. 365
Platform
  1. Windows
Glad you've sorted it & thanks for the feedback.
 

Forum statistics

Threads
1,141,476
Messages
5,706,604
Members
421,460
Latest member
Taamrak

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