Quantcast
Channel: AutoHide Cells in Excel
Viewing all articles
Browse latest Browse all 16

AutoHide Cells in Excel

$
0
0

Hi

Here is the amended code to hide empty rows. It will hid a row if it contains a formula that results in 0 or contains 0 as a number.

Rather than using sub worksheet_activate the code needs to be a procedure in a module.  You can then create your Hide Blanks button and assign this macro to the button.

The second procedure can be assigned to your Show Blanks button.

Sub HideRows() 

     Dim HiddenRow&, RowRange As Range, RowRangeValue&

      '*****************************
      '< Set the 1st & last rows to be hidden >
      Const FirstRow As Long = 1
      Const LastRow As Long = 200

      '< Set your columns that contain data >
      Const FirstCol As String = "A"
      Const LastCol As String = "G"
      '*****************************
     
      ActiveWindow.DisplayZeros = False
      Application.ScreenUpdating = False

      For HiddenRow = FirstRow To LastRow

            RowRangeValue = 0
           
            '(we're using columns A to G here)
            Set RowRange = Range(FirstCol & HiddenRow & _
                                 ":" & LastCol & HiddenRow)

            For Each rCell In RowRange
                If Len(rCell.Value) > 0 And rCell.Value <> 0 Then
                    RowRangeValue = RowRangeValue + 1
                End If
            'sums the entries in cells in the RowRange
            'RowRangeValue = Application.Sum(RowRange.Value)
           
            Next rCell
           
            If RowRangeValue <> 0 Then
                  'there's something in this row - don't hide
                  Rows(HiddenRow).EntireRow.Hidden = False
            Else
                  'there's nothing in this row yet - hide it
                  Rows(HiddenRow).EntireRow.Hidden = True
            End If

      Next HiddenRow

      Application.ScreenUpdating = True

End Sub

Sub RevealRows()
    Cells.Select
    Cells.EntireRow.AutoFit
    Range("A1").Select     

    ActiveWindow.DisplayZeros = True

End Sub


G North MMI

Viewing all articles
Browse latest Browse all 16

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>