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

AutoHide Cells in Excel

$
0
0

This is the code i was using...but the row and column information seems to be wrong.

Id like to have two buttons on the top of each page..."Hide Blanks" and "Show All."  Is that possible?  Hit "Hide Blanks" and the macro runs, hit "Show All" and the blanks reappear?  Basically, hide button to print then show all to do more editing as necessary.

Is the problem that it is referencing zeros instead of blank cells?

 

Many thanks in advance.

Option Explicit

Private Sub Worksheet_Activate()

      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

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

            'sums the entries in cells in the RowRange
            RowRangeValue = Application.Sum(RowRange.Value)

            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