Excel 一次隐藏和取消隐藏一行的按钮。类似于旋转按钮的东西

Excel 一次隐藏和取消隐藏一行的按钮。类似于旋转按钮的东西,excel,vba,excel-2007,Excel,Vba,Excel 2007,我已经搜索了很多问题,但找不到任何关于我想做什么的答案。 我想隐藏和取消隐藏行。我喜欢旋转按钮,在那个里你们可以点击上下箭头,但若那个不起作用,那个么一个按钮可以隐藏,另一个按钮可以取消隐藏 I have tried few VBA codes but none of them worked the way I want. **1st VBA code**: following code works to hide multiple rows but all at once not one

我已经搜索了很多问题,但找不到任何关于我想做什么的答案。
我想隐藏和取消隐藏行。我喜欢旋转按钮,在那个里你们可以点击上下箭头,但若那个不起作用,那个么一个按钮可以隐藏,另一个按钮可以取消隐藏

I have tried few VBA codes but none of them worked the way I want.

**1st VBA code**:  following code works to hide multiple rows but all at once not one at a time.  
If ToggleButton1.Value = True Then
 'This area contains the things you want to happen
'when the toggle button is not depressed
Rows(4).EntireRow.Hidden = True
Rows(5).EntireRow.Hidden = True
Rows(6).EntireRow.Hidden = True
Else
'This area contains the things you want to happen
'when the toggle button is depressed
Rows(4).EntireRow.Hidden = False
Rows(5).EntireRow.Hidden = False
Rows(6).EntireRow.Hidden = False
 End If
2nd VBA code: Hide and unhides just one row.
If ToggleButton1.Value = True Then
 'This area contains the things you want to happen
'when the toggle button is not depressed
Rows(4).EntireRow.Hidden = True
Else
'This area contains the things you want to happen
'when the toggle button is depressed
 Rows(4).EntireRow.Hidden = False
  End If



Someone please help!

SpinButton1
是工作表中的ActiveX spinbutton(最小值=0,最大值=10,或您希望显示/隐藏多少行)

A7这里是要显示/隐藏的行集合的顶行

代码进入工作表模块

Private Sub SpinButton1_Change()

    Dim r As Long, mx As Long
    r = Me.SpinButton1.Value
    mx = Me.SpinButton1.Max

    With Me.Range("A7")
        If r > 0 Then .Resize(r).EntireRow.Hidden = False
        If r < mx Then .Offset(r, 0).Resize(mx - r).EntireRow.Hidden = True
    End With

End Sub
Private子自旋按钮1\u Change()
变暗r为长,mx为长
r=Me.SpinButton1.Value
mx=Me.SpinButton1.Max
与我一起。范围(“A7”)
如果r>0,则.Resize(r).EntireRow.Hidden=False
如果r