Expand and Collapse Rows

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BikeToWork
    New Member
    • Jan 2012
    • 124

    Expand and Collapse Rows

    I have a spreadsheet of 75,000 rows that is sorted and grouped by AcctNum. There are several records for each AcctNum. The user wants to be able to collapse records so that only the first record for that AcctNum displays and the other records for that AcctNum are hidden. Then when the user clicks anywhere in that first AcctNum record, all of the other records for that AcctNum are displayed. Is it possible to do this? I have experience with Access and VBA, but I'm not sure how to get this done in Excel. Any advice is welcome.
  • SioSio
    Contributor
    • Dec 2019
    • 272

    #2
    Select "View Code" from the right-click menu of the tab of the sheet and write the following example code. This Example is hiding/show line range "3: 4"
    Code:
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim Cell_Adr As String
    Cell_Adr = Target.Address(RowAbsolute:=False, ColumnAbsolute:=False)
    If InStr(Target.Address, "2") Then
        Rows("3:4").Hidden = True
    Else
        Rows("3:4").Hidden = False
    End If
    End Sub

    Comment

    Working...