[英]If cell value changes, copy value to another worksheet
I created a project management template where I update the project's status on a regular basis. 我创建了一个项目管理模板,我定期更新项目的状态。
I want as soon as the cell value of one cell changes, the exact value will be copied to a cell on another worksheet. 我希望只要一个单元格的单元格值发生更改,就会将确切的值复制到另一个工作表上的单元格中。
If the cell value of the original cell is changed again (due to further project updates), I want the value to be copied again but below the previous copy, and so on. 如果原始单元格的单元格值再次更改(由于进一步的项目更新),我希望再次复制该值,但在前一个副本下面,依此类推。
As I would like to solve the problem on my own, I would be happy if you could give me some hints on how to proceed or where to look. 由于我想自己解决问题,如果你能给我一些关于如何继续或在哪里看的提示,我会很高兴。
You can use the Worksheet_Change()
event. 您可以使用
Worksheet_Change()
事件。 For example, if the cell you're changing is A1
, test to see if the Target
cell matches. 例如,如果您要更改的单元格是
A1
,请测试Target
单元格是否匹配。 If so, determine the last used row on your destination sheet ( Sheet2
, below) and then assign the value. 如果是这样,请确定目标工作表上的最后一行(
Sheet2
,下面),然后分配该值。
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Range("A1").Address Then
' Get the last row on our destination sheet (using Sheet2, col A here)...
Dim intLastRow As Long
intLastRow = Sheet2.Cells(Sheet2.Rows.Count, "A").End(xlUp).Row
' Add our value to the next row...
Sheet2.Cells(intLastRow + 1, "A") = Target.Value
End If
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.