
我有一个运行良好的宏 - 除了我必须手动运行它。
我不知道如何让它在我更改其他单元格中的值时自动运行。
Sub MonthlyMaintHideRowsWithZeroDollars()
' This Macro reads down the dollar column and hides rows with $0
' so that they do not pull into the proposal
If Range("B7").Value = "Hide" Then
Rows("7:7").EntireRow.Hidden = True
ElseIf Range("B7").Value = "Show" Then
Rows("7:7").EntireRow.Hidden = False
End If
End Sub
答案1
您正在寻找Worksheet_change
事件
当工作表上的单元格被用户或外部链接更改时发生。
例子
Sub Worksheet_Change(ByVal Target As Range)
If Range("B7").Value = "Hide" Then
Rows("7:7").EntireRow.Hidden = True
ElseIf Range("B7").Value = "Show" Then
Rows("7:7").EntireRow.Hidden = False
End If
End Sub