使用 Togglebutton Excel 2016 隐藏和取消隐藏列中带有日期的行

Hide and unhide rows with date in column using Togglebutton Excel 2016

我尝试了大约 20 种不同的代码,试图对其进行编辑以满足我的要求,但都失败了。

我有一个数据电子表格。标题为 "Complete" 的一列要么有日期,要么没有日期 (mm/dd/yyyy)。

我正在尝试编写一个代码,用于使用 ToggleButton 隐藏和取消隐藏带有日期的行,如果没有日期则保留它。

请试试这个。 假设您的日期在 E 列中。

Private Sub ToggleButton1_Click()
    Dim LastRow As Long, c As Range
    Application.EnableEvents = False
    LastRow = Cells(Cells.Rows.Count, "E").End(xlUp).Row
    If ToggleButton1.Value = True Then
        'This area contains the things you want to happen
        'when the toggle button is depressed
        For Each c In Range("E1:E" & LastRow)
    If c.Value = "" Then
        c.EntireRow.Hidden = True
    End If
    Next
    Else
    'This area contains the things you want to happen
    'when the toggle button is not depressed
        ActiveSheet.Range("E1:E" & LastRow).EntireRow.Hidden = False
    End If
End Sub

编辑 27-06-2016 稍微修改了程序以满足OP的要求。

Private Sub ToggleButton1_ClickRV()
    Dim LastRow As Long, c As Range
    Application.EnableEvents = False
    LastRow = Cells(Cells.Rows.Count, "E").End(xlUp).Row
    If ToggleButton1.Value = True Then
        'This area contains the things you want to happen
        'when the toggle button is depressed
        For Each c In Range("E1:E" & LastRow)
    If c.Value <> "" Then
        c.EntireRow.Hidden = False
    End If
    Next
    Else
    'This area contains the things you want to happen
    'when the toggle button is not depressed
        ActiveSheet.Range("E1:E" & LastRow).EntireRow.Hidden = True
    End If
End Sub