开发者

VBA: How to trigger a worksheet event function by an automatic cell change through a link?

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.

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?

Private Sub Worksheet_Change(ByVal Target As range)
  If Target.Address = "$D$9" 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


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$9" Then
        MsgBox "D9 has changed"
    ElseIf Not Intersect(rngDependents, Range("$D$9")) Is Nothing Then
            MsgBox "D9 has been changed indirectly"
    End If

End Sub


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜