[英]Excel VBA ByVal Target As Range Does not update Target Worksheet when excuting from a function cell
I'm having a issues with copying a value from a cell that is using a function to get its value from another cell. 从使用函数从另一个单元格获取其值的单元格复制值时遇到问题。 Insert value into A1, A3=A1 and when ever the value of A3 changes the changes need to transfer automatically to column H. The issues i having is that if i type the value into A1 then A3 gets updated but the values do not transfer over, if i type the value into A3 then the H column does update.
将值插入到A1中,A3 = A1,并且无论何时A3的值更改,更改都需要自动转移到H列。我遇到的问题是,如果我将值键入A1,则A3会被更新,但值不会转移,如果我将值输入A3,则H列会更新。
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Range("A3").Address Then
' Get the last row on our destination sheet (using Sheet2, col A here)...
Dim intLastRow As Long
intLastRow = Sheet1.Cells(Sheet2.Rows.Count, "H").End(xlUp).Row
' Add our value to the next row...
Sheet1.Cells(intLastRow + 1, "H") = Target.Value
End If
End Sub
I have also tried the following code. 我也尝试了以下代码。
Private Sub Worksheet_Change(ByVal Target As Range)
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Private Sub Worksheet_Change(ByVal Target As Range)
None of the above seems to trigger of the change event. 以上似乎均未触发更改事件。 Please I can not use Value A1 for the Value change it has come from A3 value change.
请我不能使用值A1进行值更改,因为它来自A3值更改。 I have even thought of running a copy and paste macro to Trigger A3.
我什至考虑过将复制和粘贴宏运行到触发器A3。 But would really like the value change code to work i can get the change value to work from A3.
但是我真的希望值更改代码能够正常工作,我可以从A3获得更改值。 Thanks in Advance.
提前致谢。
Worksheet_Change
does not fire when a cell recalculates its formula. 当单元格重新计算其公式时,不会触发
Worksheet_Change
。 It fires when a cell's Value
is assigned. 分配单元格的
Value
时触发。
If you are assigning a value to A1
, you should be looking at Range("A1").Address
in your handler. 如果要为
A1
分配值,则应在处理程序中查看Range("A1").Address
。
The are several Calculate
events, but they fire when calculation is complete for the entire sheet, not for individual cells. 这些是几个
Calculate
事件,但是当整个工作表(而不是单个单元格)的计算完成时会触发。
Try disabling events while processing your Change
. 在处理您的
Change
尝试禁用事件。 Your code might be getting itself in a loop. 您的代码可能会陷入循环。
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Address = Range("A3").Address Then
' Get the last row on our destination sheet (using Sheet2, col A here)...
Dim intLastRow As Long
intLastRow = Sheet1.Cells(Sheet2.Rows.Count, "H").End(xlUp).Row
' Add our value to the next row...
Sheet1.Cells(intLastRow + 1, "H") = Target.Value
End If
Application.EnableEvents = True
End Sub
The following script will run every time the calculation on the sheet is finished, for more info see this link and it will then update Colunm H
with the value in A3
. 每当工作表上的计算完成时,将运行以下脚本,有关更多信息,请参见此链接 ,然后
Colunm H
用A3
的值更新Colunm H
。
Not sure if it is exactly what will help but might get you on the right path. 不知道这是否真的有帮助,但是可能会让您走上正确的道路。 You can also build a check in to verify if the new
A3
value is the same at the last Column H
value and if they are then you could bypass the inserting of the value. 您还可以建立一个签入,以验证新的
A3
值在最后一个Column H
值处是否相同,如果相同,则可以跳过该值的插入。
Private Sub Worksheet_calculate()
' Get the last row on our destination sheet (using Sheet2, col A here)...
Dim intLastRow As Long
intLastRow = Sheet1.Cells(Sheet2.Rows.Count, "H").End(xlUp).Row
' Add our value to the next row...
Sheet1.Cells(intLastRow + 1, "H") = Sheet1.Range("A3").Value
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.