Results 1 to 6 of 6

Grouped rows, hide/reveal base on cell value

Threaded View

  1. #6
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Grouped rows, hide/reveal base on cell value

    Here's what I did with your sample. It's only starting point. You may want to modify as needed.

    Set up:
    1: Data validation source range: S2:S5 (S5 for blank)
    2: Added empty row after each grouping (needed to break each groups)
    3: Formula in T2:T4 to find empty rows in column (each break).
    In T2. Confirmed as array (CTRL + SHIFT + ENTER). Copied down.
    =SMALL(IF($C$11:$C$43="",ROW($C$11:$C$43)),ROW(A1))
    4: In D3 (beside validation cell) following formula
    =VLOOKUP(C3,S2:T4,2,0)
    5: In standard module following code. Rows(#).ShowDetail is used to control individual group.
    Sub ShowHideGroup(ws As Worksheet, rVal As Long)
    Dim i As Integer
    myArray = ws.Range("T2:T" & ws.Cells(Rows.Count, "T").End(xlUp).Row)
    
    For i = 1 To UBound(myArray, 1)
        If myArray(i, 1) = rVal And ws.Rows(myArray(i, 1)).ShowDetail <> True Then
            ws.Rows(rVal).ShowDetail = True
        ElseIf myArray(i, 1) <> rVal And ws.Rows(myArray(i, 1)).ShowDetail = True Then
            ws.Rows(myArray(i, 1)).ShowDetail = False
        End If
    Next i
    
    End Sub
    6: In Worksheet module (for sheet1 in this case) Me = Activesheet, RowLevels:=2 will expand all, :=1 will collapse all.
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("C3")) Is Nothing Then
        If Target.Value = "" Then
            Me.Outline.ShowLevels RowLevels:=2
        Else
            Call ShowHideGroup(Target.Parent, Target.Offset(, 1).Value)
        End If
    End If
    End Sub
    See attached sample.
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Indirectly show or hide Grouped data rows
    By Rubbertje in forum Excel General
    Replies: 2
    Last Post: 12-02-2013, 11:23 AM
  2. [SOLVED] Please help with this monster! Need help w/VBA codes to hide and unhide rows base on lists
    By SeniaHdz in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-16-2013, 12:40 PM
  3. Hide or Unhide Rows base on value in row
    By playtone22 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-22-2013, 05:54 PM
  4. [SOLVED] Show/Hide Grouped Rows/Columns
    By HangMan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-09-2012, 01:20 PM
  5. Using a listbox to hide/reveal rows.
    By graveyardshiftee in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-17-2012, 12:09 AM
  6. show/hide rows base on value
    By arnab0711 in forum Excel General
    Replies: 3
    Last Post: 06-06-2010, 10:32 AM
  7. Hide/Reveal
    By magneticgravity in forum Excel General
    Replies: 2
    Last Post: 04-09-2008, 06:34 AM
  8. Hide Row/s (single/grouped) based on cell value of column in the r
    By JB2005 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-27-2005, 05:05 PM

Tags for this Thread

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