+ Reply to Thread
Results 1 to 3 of 3

Conditionally hide rows

  1. #1
    Marc Kovner
    Guest

    Conditionally hide rows

    Any suggestions on how to conditionally hide rows on a worksheet? If a cell
    range in a row has a non-zero sum quantity I want to display the entire row
    and hide all rows that have zero quantity sum in the cell range of that row.

  2. #2
    Norman Jones
    Guest

    Re: Conditionally hide rows

    Hi Marc,

    Try:
    '=================>>
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rw As Range
    Dim i As Long
    Const StartCol As String = "B" '<<==== CHANGE
    Const EndCol As String = "I" '<<==== CHANGE

    If Not Intersect(Target, Columns(StartCol & _
    ":" & EndCol)) Is Nothing Then
    For Each rw In Target.Rows
    i = rw.Row
    Rows(i).Hidden = Application.Sum(Range(Cells _
    (i, StartCol), Cells(i, EndCol))) = 0
    Next rw
    End If

    End Sub
    '<<================

    Cgange the StartCol and EndCol values to suit.
    ..
    This is worksheet event code and should be pasted into the worksheets's
    code module (not a standard module and not the workbook's ThisWorkbook
    module):

    *********************************
    Right-click the worksheet's tab

    Select 'View Code' from the menu and paste the code.

    Alt-F11 to return to Excel.
    *********************************


    ---
    Regards,
    Norman



    "Marc Kovner" <Marc [email protected]> wrote in message
    news:[email protected]...
    > Any suggestions on how to conditionally hide rows on a worksheet? If a
    > cell
    > range in a row has a non-zero sum quantity I want to display the entire
    > row
    > and hide all rows that have zero quantity sum in the cell range of that
    > row.




  3. #3
    Norman Jones
    Guest

    Re: Conditionally hide rows

    Hi Marc,

    To allow for formula and non-formula changes, better would be:

    '=================>>
    Private Sub Worksheet_Calculate()
    Dim rw As Range
    Dim i As Long
    Dim rng As Range

    Set rng = Range("B2:I20") '<<==== CHANGE

    For Each rw In rng.Rows
    i = rw.Row
    Rows(i).Hidden = Application.Sum(rw) = 0
    Next rw

    End Sub
    '<<=================

    '=================>>
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rng As Range
    Dim rw As Range
    Dim i As Long

    Set rng = Range("B2:I20") '<<==== CHANGE'

    If Not Intersect(Target, rng) Is Nothing Then
    For Each rw In Target.Rows
    i = rw.Row
    Rows(i).Hidden = Application.Sum(rw) = 0
    Next rw
    End If

    End Sub
    '<<=================

    Change the address of the rng variable to suit.

    Again, these are event procedures and should be pasted into the code module
    behind the worksheet.


    ---
    Regards,
    Norman



    "Norman Jones" <[email protected]> wrote in message
    news:e%[email protected]...
    > Hi Marc,
    >
    > Try:
    > '=================>>
    > Private Sub Worksheet_Change(ByVal Target As Range)
    > Dim rw As Range
    > Dim i As Long
    > Const StartCol As String = "B" '<<==== CHANGE
    > Const EndCol As String = "I" '<<==== CHANGE
    >
    > If Not Intersect(Target, Columns(StartCol & _
    > ":" & EndCol)) Is Nothing Then
    > For Each rw In Target.Rows
    > i = rw.Row
    > Rows(i).Hidden = Application.Sum(Range(Cells _
    > (i, StartCol), Cells(i, EndCol))) = 0
    > Next rw
    > End If
    >
    > End Sub
    > '<<================
    >
    > Cgange the StartCol and EndCol values to suit.
    > .
    > This is worksheet event code and should be pasted into the worksheets's
    > code module (not a standard module and not the workbook's ThisWorkbook
    > module):
    >
    > *********************************
    > Right-click the worksheet's tab
    >
    > Select 'View Code' from the menu and paste the code.
    >
    > Alt-F11 to return to Excel.
    > *********************************
    >
    >
    > ---
    > Regards,
    > Norman
    >
    >
    >
    > "Marc Kovner" <Marc [email protected]> wrote in message
    > news:[email protected]...
    >> Any suggestions on how to conditionally hide rows on a worksheet? If a
    >> cell
    >> range in a row has a non-zero sum quantity I want to display the entire
    >> row
    >> and hide all rows that have zero quantity sum in the cell range of that
    >> row.

    >
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1