Suppressing Zero Rows

We had the same issue with suppressing zero rows once the report is run out and wanted to share our solution.

Background:  The ZeroFill function is used to suppress rows which have zero value in a particular column in the Excel Workbook.

If a parameter is changed once the Workbook is opened macros have been developed to perform this functionality.

The ones we started using (from this forum) were:

Sub HideZeroRows()

Dim rng As Range
Dim cnt As Long
Dim lmt As Integer
Dim opt As Integer

lmt = 10000 'set the limit for when warning appears
Set rng = Selection 'set current selection to a variable
cnt = rng.Count

If cnt > lmt Then
opt = MsgBox("You have made a large selection and will take some time for your Macro to run. Click Yes to continue or No to make a smaller selection.", vbYesNo, "Warning")
End If
If cnt <= lmt Or (cnt > lmt And opt = vbYes) Then
For Each cell In rng
If (Not IsEmpty(cell) And cell.Value = 0) Then
cell.EntireRow.Hidden = True
End If
Next
End If

End Sub

Sub ShowZeroRows()

Dim rng As Range
Dim cnt As Long
Dim lmt As Integer
Dim opt As Integer

lmt = 10000 'set the limit for when warning appears
Set rng = Selection 'set current selection to a variable
cnt = rng.Count

If cnt > lmt Then
opt = MsgBox("You have made a large selection and will take some time for your Macro to run. Click Yes to continue or No to make a smaller selection.", vbYesNo, "Warning")
End If
If cnt <= lmt Or (cnt > lmt And opt = vbYes) Then
For Each cell In rng
If (Not IsEmpty(cell) And cell.Value = 0) Then
cell.EntireRow.Hidden = False
End If
Next
End If

End Sub

To use this the ShowZeroRows and HideZeroRows macros would have to be called.

We found some limitations to this, primarily for Workbooks with many worksheets, as the macros needed to be added to each.

Our solution was to replace these two macros with one which would only be needed at the worksheet level and only require one macro to be executed.

We have in fact removed the zeroFill function and just use the macro once the report is run out

Sub ShowCorrectFormat()
    Dim Current As Worksheet
    Dim rng As Range
   
    For Each Current In Worksheets
        'MsgBox Current.Name
        Set rng = Current.Range("M14", "M475")  -- can be replaced by Set rng = Selection  to allow users to specify exact range.  Want to limit the range as much as possible for speed.
        For Each cell In rng
            If (cell.EntireRow.Hidden) = True Then
                cell.EntireRow.Hidden = False
            End If
        Next
       
        For Each cell In rng
            If (Not IsEmpty(cell) And cell.Value = 0) Then
                cell.EntireRow.Hidden = True
            End If
        Next
     Next
       
End Sub

Hope this is helpful