|
|
|
|
|
|
Excel
|
Hide Empty Rows, Unhide Others
|
|
Ease of Use
|
Intermediate
|
Version tested with
|
2000, 2003
|
Submitted by:
|
johnske
|
Description:
|
All specified unused rows are hidden when the sheet is activated and all specified used rows are unhidden
|
Discussion:
|
You may have a summary sheet where, for ease of reading, you only want rows with non-zero entries to be shown.
|
Code:
|
instructions for use
|
Option Explicit
Private Sub Worksheet_Activate()
Dim HiddenRow&, RowRange As Range, RowRangeValue&
Const FirstRow As Long = 4
Const LastRow As Long = 20
Const FirstCol As String = "B"
Const LastCol As String = "G"
ActiveWindow.DisplayZeros = False
Application.ScreenUpdating = False
For HiddenRow = FirstRow To LastRow
Set RowRange = Range(FirstCol & HiddenRow & _
":" & LastCol & HiddenRow)
RowRangeValue = Application.Sum(RowRange.Value)
If RowRangeValue <> 0 Then
Rows(HiddenRow).EntireRow.Hidden = False
Else
Rows(HiddenRow).EntireRow.Hidden = True
End If
Next HiddenRow
Application.ScreenUpdating = True
End Sub
|
How to use:
|
- Open an Excel workbook
- Select Tools/Macro/Visual Basic Editor
- In the VBE window, select Tools/Project Explorer
- Select the worksheet module for the linked sheet
- Copy and paste the code into this Module
- Now select File/Close and Return To Microsoft Excel
- Save your changes...
|
Test the code:
|
- Download the attachment to test the code
- Sheet2 contains links to Sheet1, note that some rows are hidden
- (You can select all and Right-click and then choose Unhide to view all)
- Go to Sheet1 and enter a value in any unused row
- Now look at Sheet2 and note this same (numbered) row is now visible
|
Sample File:
|
HideBlankLinkedRows.zip 8.94KB
|
Approved by mdmackillop
|
This entry has been viewed 240 times.
|
|