按钮,可以一次隐藏和取消隐藏一行.类似旋转按钮的东西



我搜索了很多问题,但找不到我想做什么的答案。
我想隐藏和取消隐藏行。我喜欢旋转按钮,你可以点击上下箭头,但如果这不起作用,那么一个按钮隐藏,另一个按钮取消隐藏。

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旋转按钮-工作表(最小值=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

最新更新