Hello JamesT1,
I added a Toggle Button to "Sheet1" to allow you to hide and view the rows. You can remove the button if you like and just the macros in your code. Here are the macros that have been added to the attached workbook.
Toggle Button Macro
Private Sub ToggleButton1_Click()
With ToggleButton1
If .Value = False Then
.Caption = "Hide Empty Rows"
Call ShowAllRows
Else
.Caption = "Show All Rows"
Call HideEmptyRows
End If
End With
End Sub
Hide Rows and Show Rows Macros
Sub HideEmptyRows()
Dim LastRow As Long
Dim Rng As Range
Dim RngEnd As Range
Set Rng = Worksheets("Sheet1").Range("A6")
Set RngEnd = Rng.Parent.Cells(Rows.Count, Rng.Column).End(xlUp)
Set Rng = IIf(RngEnd.Row < Rng.Row, Rng, Rng.Parent.Range(Rng, RngEnd))
LastRow = Rng.Find("*", , xlValues, xlWhole, xlByRows, xlPrevious, False).Row
If LastRow < RngEnd.Row Then
Rng.Parent.Range(Rows(LastRow + 1), Rows(RngEnd.Row)).Hidden = True
End If
End Sub
Sub ShowAllRows()
Dim EndRow As Long
Dim Rng As Range
Dim StartRow As Long
On Error GoTo ExitOut
With Worksheets("Sheet1")
Set Rng = .Columns(1).Cells.SpecialCells(xlCellTypeVisible)
StartRow = Rng.Areas(1).Rows.Count
EndRow = Rng.Areas(2).Row
.Range(Rows(StartRow), Rows(EndRow)).EntireRow.Hidden = False
End With
ExitOut:
End Sub
Bookmarks