简体   繁体   English

特定列中所选单元格的VBA复制值

[英]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.

相关问题 VBA将Word Doc中的下拉列表的选定值复制到特定的Excel单元格中 - VBA to copy selected value of dropdown in Word Doc into specific Excel cell VBA代码可将值从一个单元格复制到特定列 - VBA code to copy value from one cell to specific column VBA复制特定的单元格并粘贴到相邻列中 - VBA to copy a specific cell and paste into adjacent column vba代码以查找特定值并在该列的后续单元格中复制值并粘贴到新工作表中 - vba code to find a specific value and copy value in subsequent cell in the column and paste in a new sheet VBA Excel:宏,该宏在一行中搜索特定单元格中的某个变量值,然后将值复制并粘贴到此列中 - VBA Excel : Macro that searches a row for a certain variable value from specific cell and then copy&pastes value to this column VBA:根据单元格值从选定的工作簿中复制粘贴 - VBA: copy paste from selected workbooks based on cell value VBA 复制范围直到单元格值 = 特定文本/值 - VBA Copy Range Until Cell Value = specific text/value VBA,循环列和复制单元格格式(如果值与其他列匹配) - VBA, loop column and copy cell format if value match in other column Excel VBA从列复制值并将值粘贴到单元格中 - excel vba copy value from a column and paste value in a cell Excel VBA,如果单元格不是数字且列中为空,则选定单元格复制并粘贴到另一列 - Excel VBA, If cell is not numeric and empty in a column, selected cell copy and paste to another column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM