This works and is fast. Let me know if you have questions about how the code works. See attached.
Option Explicit
Private Sub HideUnhide_Click()
Dim ws As Worksheet
Dim lastC As Long
Dim lastR As Long
Dim scanRow As Long
Dim scanCol As Long
Dim HideIt As Boolean
Dim NoNumerics As Boolean
Dim AllBlank As Boolean
For Each ws In Worksheets
If Not HideUnhide Then
' Rows are hidden. Unhide.
ws.Cells.EntireRow.Hidden = False
Else
lastC = LastColumn(ws)
lastR = LastRow(ws)
If lastC <> 0 And lastR <> 0 Then
For scanRow = 1 To lastR
HideIt = True
NoNumerics = True
AllBlank = True
For scanCol = 1 To lastC
If Not IsEmpty(ws.Cells(scanRow, scanCol)) Then
AllBlank = False
If IsNumeric(ws.Cells(scanRow, scanCol)) Then
NoNumerics = False
If ws.Cells(scanRow, scanCol) <> 0 Then
HideIt = False
Exit For
End If
End If
End If
Next scanCol
If HideIt And Not NoNumerics And Not AllBlank Then
ws.Cells(scanRow, 1).EntireRow.Hidden = True
End If
Next scanRow
End If
End If
Next ws
End Sub
Function LastRow(ws As Worksheet) As Long
If WorksheetFunction.CountA(ws.Cells) > 0 Then
'Search for any entry, by searching backwards by Rows.
LastRow = ws.Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
End If
End Function
Function LastColumn(ws As Worksheet) As Long
If WorksheetFunction.CountA(ws.Cells) > 0 Then
'Search for any entry, by searching backwards by Columns.
LastColumn = ws.Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
End If
End Function
Bookmarks