Hi,

I have written a macro to hide blank rows. The macro is as follows:

Sub Before_print()
Dim i As Long, nr As Long
Dim c, rng As Range
With Sheets("Sheet1")
nr = Application.WorksheetFunction.CountA(Range("A:A"))
For i = 1 To 40
If IsEmpty(Cells(i, 1)) Or Cells(i, 1) = 0 Then
Cells(i, 1).EntireRow.Hidden = True
End If
Next i
End With
End Sub

The macro works fine, but the same does not work when the worksheet is protected (some cells are hidden as well as protected).
It gives the following error:

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

Please help on this. Thanks in advance.