Error Message: Run Time Error '1004': Unable to set the Hidden property of the Range class

r0bism123

Board Regular
Joined
Feb 8, 2018
Messages
57
First, let me say thanks in advance for looking at this for me. I've been racking my brain trying to figure this out error and I'm stuck.

Below is my code which I am getting the, "Run Time Error '1004': Unable to set the Hidden property of the Range class". What is interesting is that the rows hide/unhide as commanded THEN I get the error message. Annoying. I get the error on line: c.EntireRow.Hidden = True

Thanks again!

Sub Hide_Rows_Containing_Value_All_Sheets()

Dim c As Range
Dim ws As Worksheet

For Each ws In ActiveWorkbook.Worksheets
For Each c In ws.Range("A16:A83").Cells
If c.Value = "" Then
c.EntireRow.Hidden = True
End If
Next c
Next ws

End Sub

Sub Unhide_All_Rows()

For Each ws In ActiveWorkbook.Worksheets
For Each c In ws.Range("A16:A83").Cells
If c.Value = "" Then
c.EntireRow.Hidden = False
End If
Next c
Next ws

End Sub


 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Are any of your sheets protected?
 
Upvote 0
Yes, all of my pages are protected and I read something on another site about protected sheets causing issues. So, I tried to unprotecting the workbook and it resulted in Excel crashing. I would get the hour-glass on my cursor and I have to force close it.
 
Upvote 0
Try
Code:
Sub Hide_Rows_Containing_Value_All_Sheets()

   Dim c As Range
   Dim ws As Worksheet
   
   For Each ws In ActiveWorkbook.Worksheets
      ws.Unprotect "[COLOR=#ff0000]Pword[/COLOR]"
      For Each c In ws.Range("A16:A83").Cells
         If c.Value = "" Then
         c.EntireRow.Hidden = True
         End If
      Next c
      ws.Protect "[COLOR=#ff0000]Pword[/COLOR]"
   Next ws

End Sub
Change the values in red to match your password.
If Col A has values rather than a formula, this should be quicker
Code:
Sub Hide_Rows_Containing_Value_All_Sheets()

   Dim ws As Worksheet
   
   For Each ws In ActiveWorkbook.Worksheets
      ws.Unprotect "Pword"
      ws.Range("A16:A83").SpecialCells(xlBlanks).EntireRow.Hidden = True
      ws.Protect "Pword"
   Next ws

End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,162
Members
453,021
Latest member
Justyna P

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