Excel事件更改:隐藏或取消隐藏行

时间:2015-05-15 22:57:00

标签: excel-vba events vba excel

我一直在尝试运行以下代码,但每当我在第一列中将值更改为0时,都没有任何反应。

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

Dim wb_afskrivninger As Workbook
Dim ws_afskrivningsberegning As Worksheet

Set wb_afskrivninger = ActiveWorkbook
Set ws_afskrivningsberegning = ThisWorkbook.Sheets("afskrivningsberegning")

Dim columnI_rowcount As Long

columnI_rowcount = ws_afskrivningsberegning.Range("I" & Rows.Count).End(xlUp).Row

Dim columnI_0count As Long

Application.ScreenUpdating = False

For columnI_0count = 0 To column_rowcount

    If ws_afskrivningsberegning.Range("I" & columnI_rowcount) = 0 Then
        Rows(columnI_rowcount).EntireRow.Hidden = True
        Else: Rows(columnI_rowcount).EntireRow.Hidden = False
    End If

Next columnI_0count

Application.ScreenUpdating = True

End Sub

帮助将不胜感激。

提前致谢。

1 个答案:

答案 0 :(得分:0)

将其放在工作表模块中,右键单击工作表选项卡并选择“查看代码”,然后在此处复制并粘贴此代码。将msgbox行替换为目标变为0时要使用的任何代码

list.append()

如果您正在寻找隐藏= 0行的代码,请尝试使用

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    If Target.Column = 9 Then ' this is column "I"
        If Target = 0 Then
            MsgBox "You have changed the target value to Zero"
        End If
    End If
End Sub