[英]How to copy and paste a cell value to another worksheet in the same workbook
Currently I am working on making a macro that needs does the following things. 目前,我正在制作一个需要执行以下操作的宏。
1) It looks through the top row, returning a named column 1)通过第一行查找,返回一个命名列
2) It then selects this column 2)然后选择此列
3) Then it loops through column looking for the first value greater than zero. 3)然后,它遍历列以查找第一个大于零的值。
4) I then take the row value of this "first" instance 4)然后我取这个“第一个”实例的行值
5) From my public variables, I get a column value (#'s) 5)从我的公共变量中,我得到一个列值(#)
6) I combine the row value and column value to find my "data point" 6)我结合行值和列值来找到我的“数据点”
Finally I want copy this value to another worksheet in the same workbook called "Critical Signals" 最后,我想将此值复制到同一工作簿中名为“关键信号”的另一个工作表中
This is where I'm having trouble. 这是我遇到麻烦的地方。 Everytime I run my code I get a error "1004".
每次运行代码时,都会出现错误“ 1004”。 I can't seem to copy and paste my selected cell to my second worksheet.
我似乎无法将所选单元格复制并粘贴到第二个工作表中。 Any ideas?
有任何想法吗?
Sub Locate_Start_Of_Test()
'Use the Find Method to identify signal columns
Dim SigCol As Integer
Dim SigRow As Integer
Dim Cell As Range
Dim CritRow As Integer
'Variables to hold critical point of Start of Test
SigRow = 1 'Row Location of Signal Names
SigCol = Sheet1.Cells(SigRow, 1).EntireRow.Find(What:="EngAout_N_Actl (rpm)", LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext).Column
'SigCol now holds the value of rpm column
Columns(SigCol).Select
CritRow = 1
For Each Cell In Selection
If Cell.Value > 0 And Cell.Value <> "EngAout_N_Actl (rpm)" Then
Exit For
End If
CritRow = CritRow + 1
Next Cell
Sheets(1).Range(Cells(CritRow, Trip_point)).Copy
Sheets("Critical Signals").Activate
Range("E4").Select
ActiveSheet.Paste
End Sub
You are close, simply remove Range
from this line: 您已接近,只需从此行中删除
Range
:
Sheets(1).Range(Cells(CritRow, Trip_point)).Copy
So that it looks like this: 这样看起来像这样:
Sheets(1).Cells(CritRow, Trip_point).Copy
Also, I'd recommend not using Active
or Select
statements. 另外,我建议不要使用
Active
或Select
语句。 For example your 4 lines of code to copy and paste could look like this instead: 例如,您要复制和粘贴的4行代码可能看起来像这样:
Sheets("Critical Signals").Range("E4") = Sheets(1).Cells(CritRow, Trip_point)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.