VBA:如何通过链接自动更改单元格来触发工作表事件功能?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2735435/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA: How to trigger a worksheet event function by an automatic cell change through a link?
提问by Ibhar
My problem is the following: The function below triggers an "if then function" when i manually change the value in cell D9. What should I do to get it to work with an automatic value change of cell D9 trough a link.
我的问题如下:当我手动更改单元格 D9 中的值时,下面的函数会触发“if then 函数”。我应该怎么做才能让它通过链接与单元格 D9 的自动值更改一起使用。
In other words if i where to link cell D9 to cell A1 and change the value of A1 can i still make the function below work?
换句话说,如果我在哪里将单元格 D9 链接到单元格 A1 并更改 A1 的值,我仍然可以使下面的功能工作吗?
Private Sub Worksheet_Change(ByVal Target As range)
If Target.Address = "$D" Then
If range("C12") = 0 Then
Rows("12:12").Select
Selection.RowHeight = 0
Else:
Rows("12:12").Select
Selection.RowHeight = 15
End If
End Sub
回答by dendarii
How about something like this:
这样的事情怎么样:
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
Dim rngDependents As Range
Set rngDependents = Target.Dependents
If Target.Address = "$D" Then
MsgBox "D9 has changed"
ElseIf Not Intersect(rngDependents, Range("$D")) Is Nothing Then
MsgBox "D9 has been changed indirectly"
End If
End Sub
回答by Ibhar
try to make your function then in other cell use the function with input the link to the cell d9. When you change the value at cell d9 your function will be evaluated.
尝试使您的函数然后在其他单元格中使用该函数并输入单元格 d9 的链接。当您更改单元格 d9 中的值时,您的函数将被评估。