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

AutoHide Cells in Excel

$
0
0

G North.  The code has been working like a charm, but one worksheet will not work from some reason.  I want to hide all rows which contain a 0 in column D.  Row range is 10 to 500.  Any idea why this code won't work?  The 0's in columns D, E & F disappear but the rows don't.  What do you think?

 

Sub HideRows()

 

     Dim HiddenRow&, RowRange As Range, RowRangeValue&

 

      '*****************************

      '< Set the 1st & last rows to be hidden >

      Const FirstRow As Long = 10

      Const LastRow As Long = 900

 

      '< Set your columns that contain data >

      Const FirstCol As String = "D"

      Const LastCol As String = "D"

      '*****************************

 

      ActiveWindow.DisplayZeros = False

      Application.ScreenUpdating = False

 

      For HiddenRow = FirstRow To LastRow

 

            RowRangeValue = 0

 

            '(we're using columns D to D here)

            Set RowRange = Range(FirstCol & HiddenRow & _

                                 ":" & LastCol & HiddenRow)

 

            For Each rCell In RowRange

                If 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


Viewing all articles
Browse latest Browse all 16

Trending Articles



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