user785099
user785099

Reputation: 5573

How to expand the hidden rows in excel using vba?

I have a spreadsheet, which has 100 rows. Among these 100 rows, only 10 rows are required to be displayed at first, other 90 rows should be collapsed(hidden) at first. If user wants to read the whole 100 rows, he/she can click the button to expand the spreadsheet of 10 rows to 100 rows. How to implement this kind of function in VBA?

Upvotes: 2

Views: 1838

Answers (1)

Reafidy
Reafidy

Reputation: 8481

You could use a command button:

Private Sub CommandButton1_Click()

    '// Label button "Show Rows"
    With Me.CommandButton1
        If .Caption = "Show Rows" Then
            .Caption = "Hide Rows"
            Rows("11:100").Hidden = False
        Else
            .Caption = "Show Rows"
            Rows("11:100").Hidden = True
        End If
    End With

End Sub

Or a toggle button:

Private Sub ToggleButton1_Click()
    '// Label Something Like "Show/Hide Rows"
    Rows("11:100").Hidden = Not ToggleButton1.Value
End Sub

Upvotes: 3

Related Questions