Replace your current HideRows function with this:
Sub HideRows()
UpdateStatusBar "Adjusting the calendar"
Application.ScreenUpdating = False
Dim iStart As Long
Dim iEnd As Long
Dim iLast As Long
Dim iRow As Long
Dim sName As String
' get the sheet name to pass to the row and column functions
sName = ActiveSheet.Name
' show all hidden rows
ActiveSheet.Rows.Hidden = False
' get the last row on the sheet
iLast = GetLastRow(sName)
' loop through all the groups checking them, change 11 to the group size if it changes in the future
' the first group starts at 7 so change if it changes in the future
For iStart = 7 To iLast Step 11
' set the start and end rows for the data, change the + 10 if the group size changes in the future
iRow = iStart + 2
iEnd = iStart + 10
' if the first row has data, hide only the empty rows
If GetLastColumnByRow(sName, iRow) > 0 Then
' loop through the rows
For iRow = (iStart + 2) To iEnd Step 1
' if the row is blank, hide it
If GetLastColumnByRow(sName, iRow) = 0 Then
ActiveSheet.Rows(iRow).Hidden = True
End If
Next
' else hide the group
Else
ActiveSheet.Rows(iStart & ":" & iEnd).Hidden = True
End If
Next
Application.ScreenUpdating = True
UpdateStatusBar "Finished adjusting the calendar"
End Sub
Function GetLastRow(sSheet As String) As Long
On Error GoTo NoRow
Dim iReturn As Long
iReturn = Worksheets(sSheet).Cells.Find("*", Searchorder:=xlByRows, SearchDirection:=xlPrevious).Row
GoTo FinishUp
NoRow:
iReturn = 0
GoTo FinishUp
FinishUp:
GetLastRow = iReturn
End Function
Function GetLastColumnByRow(sSheet As String, iRowToUse As Long) As Long
On Error GoTo NoCol
Dim iReturn As Long
iReturn = Sheets(sSheet).Rows(iRowToUse).Find(What:="*", LookIn:=xlValues, LookAt:=xlWhole, Searchorder:=xlByColumns, SearchDirection:=xlPrevious).Column
GoTo FinishUp
NoCol:
iReturn = 0
GoTo FinishUp
FinishUp:
GetLastColumnByRow = iReturn
End Function
Sub UpdateStatusBar(sText As String)
Application.DisplayStatusBar = True
Application.StatusBar = sText
End Sub
I like to use the status bar to show information about what is currently happening to the user. You can remove it if you want.
Bookmarks