I'm getting the following error msg: run-time error '438', Object doesn't support this property or method.

The function below should loop through the first column and hide the row if "x" exists. The sheet will have a formula on the first column that will evaluate if there is data returned. The sheet is an accounting balance sheet and some accounts do not return data so I would like to hide it. If there is a better way please let me know, this is the simplest piece of code that I can understand.


Function hidrows()
Template.ActiveSheet.Protection.Enabled = False
Template.ActiveSheet.Calculate

For intRow = 1 To Template.ActiveSheet.UsedRange.Rows.Count
    If Template.Cells(intRow, 1).Value = "X" Or Template.Cells(intRow, 1).Value = "x" Then
        For intCol = 1 To Template.ActiveSheet.UsedRange.Columns.Count
            If Template.Rows(intRow).EntireRow.Hidden = False Then
                Template.Rows(intRow).EntireRow.Hidden = True
            End If
        Next
    End If
Next

Template.ActiveSheet.Protection.Enabled = True

End Function