Button to hide/unhide all empty rows? (Excel 97)
Hello, I am very new to macros so please bear with me. I am trying to make a button to hide all the empty rows and another to unhide them for a report in Excel 97. I have tried using two command buttons but toggle would work too. In any case I am not sure how to proceed. I have code I have tried to adapt from another macro I found on this site that hides all empty rows upon activating the sheet. However I get a runtime error '1004' application-defined or object defined error near the bottom (red text). However I thought it was defined for hiddenrow? As it isn't working I must be wrong however I am not sure how to fix it.
Any ideas would be greatly appreciated.
Code:
Private Sub CommandButton2_Click()
If CommandButton2.Value = True Then
Dim HiddenRow&, RowRange As Range, RowRangeValue&
Const FirstRow As Long = 4
Const LastRow As Long = 180
Const FirstCol As String = "A"
Const LastCol As String = "O"
ActiveWindow.DisplayZeros = False
Application.ScreenUpdating = False
For HiddenRow = FirstRow To LastRow
Set RowRange = Range(FirstCol & HiddenRow & _
":" & LastCol & HiddenRow)
RowRangeValue = Application.Sum(RowRange.Value)
If RowRangeValue <> 0 Then
Rows(HiddenRow).EntireRow.Hidden = False
Else
Rows(HiddenRow).EntireRow.Hidden = True
End If
Next HiddenRow
Else
Rows(HiddenRow).EntireRow.Hidden = False
End If
ActiveWindow.DisplayZeros = True
Application.ScreenUpdating = True
End Sub
Thanks