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?
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
精彩评论