[英]VBA copy value of selected cell in specific column
I've been looking for a way to code in VBA: when I click on a certain cell in range X10:X5000, Excel should copy that cell value to a specific cell B10. 我一直在寻找一种在VBA中编码的方法:当我单击范围X10:X5000中的某个单元格时,Excel应该将该单元格值复制到特定的单元格B10中。
Currently I have the following, but it only works when the cell I select is an actual value. 目前,我有以下内容,但仅在我选择的单元格为实际值时才有效。 When the cell I select is the outcome of a formula, the target cell shows the value for a fraction of a second and then the cell becomes blank.
当我选择的单元格是公式的结果时,目标单元格会显示该值的几分之一秒,然后该单元格将变为空白。
So how can I make sure I always copy the value of the selected cell and not the formula? 那么,如何确保始终复制所选单元格的值而不是公式的值? In the example, I did not take into account the range, but only a selected column.
在示例中,我没有考虑范围,仅考虑了选定的列。
Thanks for the help! 谢谢您的帮助!
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column = 19 Then ' check if cell modifed is in column "S"
Target.Copy Range("B10")
End If
End Sub
Thanks! 谢谢!
Try using 尝试使用
Range("B10").Value = Target.Value
instead of 代替
Target.Copy Range("B10")
This should transfer the value across, instead of the formula 这应该传递值,而不是公式
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.