繼我的評論看到這個。我已經評論了代碼,所以你不會有理解它的問題。但是,如果你這樣做,然後只是問。 :)
Dim PrevValue As Variant
Private Sub Worksheet_Change(ByVal Target As Range)
'~~> Check if more than 1 cell is changed
If Target.Cells.CountLarge > 1 Then Exit Sub
'~~> Check if the change didn't happen in A1
If Not Intersect(Target, Range("A1")) Is Nothing Then Exit Sub
On Error GoTo Whoa
Application.EnableEvents = False
'~~> Compare
If Target.Value <> PrevValue Then
Range("A1").Value = "Value of " & Target.Address & " changed from " & _
PrevValue & " to " & Target.Value
'~~> Store new value to previous value
PrevValue = Target.Value
End If
Letscontinue:
Application.EnableEvents = True
Exit Sub
Whoa:
MsgBox Err.Description
Resume Letscontinue
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
PrevValue = Target.Value
End Sub
在'_Selection'更改事件存儲單元的值在'變量'中。在'_Change'事件中,只需比較'target.value'和那個'variable'。另外,由於您在'_Change'事件中正在寫入單元格,因此您可能需要關閉事件以防止可能的無限循環。你可能想看到[This](http://stackoverflow.com/questions/13860894/ms-excel-crashes-when-vba-code-runs/13861640#13861640) –
在我上面的評論中,我假設你只想捕獲單個單元格值。如果有多個單元格,那麼你將不得不使用一個數組變量。 –
從相反的角度思考這個問題,明確Cell(「A1」)'的價值是什麼?第一個改變的單元格將會設置它,但是在什麼時候它不再這麼說呢? (也許你有這個覆蓋,這只是第一個彈出到我的頭......) – FreeMan