2017-03-16 55 views
0
Private Sub Assumption1Change(ByVal Target As Range) 
    Application.EnableEvents = False 
    On Error GoTo ErrHandler 

    If Target.Text = "D10" Then 
    Range("B10").Formula = "=Now()" 
    Else 
    End If 

    Applicatoin.EnableEvents = True 
End Sub 

我使用上面的代碼插入函數到單元格,如果在價值另一細胞的變化,雖然我不能得到它的工作單元。任何人都可以將我指向正確的方向嗎?插入功能,如果另一個細胞變化的價值

回答

1

嘗試下面的代碼,只要確保你把它放在正確的工作你想要的工作:

Private Sub Worksheet_Change(ByVal Target As Range) 

    Application.EnableEvents = False 

    If Not Intersect(Range("D10"), Target) Is Nothing Then 
     Target.Offset(, -2).Formula = "=Now()" '<-- place the formula 2 columns to the left of the cell you just modified 
    End If 

    Application.EnableEvents = True ' <-- restore original setting 

End Sub 
+0

只是一個小外接:這樣的如果,結束如果塊它會是邏輯上更乾淨,以便將兩個Application.EnableEvents語句放入其中 – user3598756