I have the following code in a worksheet:
Private Sub Worksheet_Calculate()
Module1.UnProtectIt
Rows("4").Select
Selection.EntireRow.Hidden = False
Dim r As Range
For Each r In Range("AS4:BP4")
r.EntireColumn.Hidden = (r.Value = "No")
Next
Rows("4").Select
Selection.EntireRow.Hidden = True
Module1.ProtectIt
End Sub
The code is intended to unprotect the worksheet, unhide row 4, evaluate a formula in cells AS4:BP4 for either a "Show" or "No" value returned, and then hide columns based on those that return "No". The code should then re-hide row 4 and re-protect the worksheet.
When I initiate the code, it fails at "Rows("4").Select". If I try to run the code without unhiding this row, it fails at "r.EntireColumn.Hidden = (r.Value = "No")".
Any ideas?
Private Sub Worksheet_Calculate()
Module1.UnProtectIt
Rows("4").Select
Selection.EntireRow.Hidden = False
Dim r As Range
For Each r In Range("AS4:BP4")
r.EntireColumn.Hidden = (r.Value = "No")
Next
Rows("4").Select
Selection.EntireRow.Hidden = True
Module1.ProtectIt
End Sub
The code is intended to unprotect the worksheet, unhide row 4, evaluate a formula in cells AS4:BP4 for either a "Show" or "No" value returned, and then hide columns based on those that return "No". The code should then re-hide row 4 and re-protect the worksheet.
When I initiate the code, it fails at "Rows("4").Select". If I try to run the code without unhiding this row, it fails at "r.EntireColumn.Hidden = (r.Value = "No")".
Any ideas?