[英]Capture all changing data from a cell to another using excel VBA
我的工作簿的sheet1 A1單元不斷更新新數據,並且捕獲了所有更改並將我的要求保存到sheet2的“ B”列中。(新數據將添加到新行,例如B1,B2,B3等)中,使用下面的代碼I能夠使用工作表更改功能來實現
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Range("A1").Address Then
Dim intLastRow As Long
intLastRow = Sheet2.Cells(Sheet2.Rows.Count, "B").End(xlUp).Row
Sheet2.Cells(intLastRow + 1, "B") = Target.Value
End If
End Sub
如果我手動將數據輸入到原始單元格(sheet1 A1),則此代碼將非常有效。 但是,如果我使用任何公式說“ = C2”,則它不起作用。 在sheet2 B上沒有捕獲使用公式更新的任何數據。想知道我是否也可以捕獲使用公式更新的值
Private Sub Worksheet_Calculate()
With Sheet2
With .Cells(.Rows.Count, "B").End(xlUp)
If .Value <> Sheet1.Range("A1").Value Then
.Offset(1).Value = Sheet1.Range("A1").Value
End If
End With
End With
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.