简体   繁体   English

如何将单元格值复制并粘贴到同一工作簿中的另一个工作表

[英]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. 另外,我建议不要使用ActiveSelect语句。 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.

相关问题 如何通过匹配单元格值将范围复制并粘贴到另一个工作表 - How to copy and paste a range to another worksheet by matching a cell value VBA:如果工作簿中的工作表名称等于从用户窗体中选择的组合框值,则复制该工作表并将其粘贴到另一个工作簿中 - VBA: If Worksheet name in Workbook equals Combo Box value selected from Userform then copy that Worksheet and paste it into another Workbook 将单元格值转移到另一个工作表,而无需复制和粘贴? - Transfer cell value to another worksheet without copy and paste? 将一个单元格从一个工作表复制并粘贴到另一个工作表,然后乘以一个值 - copy and paste a cell from one worksheet to another and multiply it by a value 如何将单元格值存储在变量中,删除相同的单元格值然后将其粘贴到另一个工作簿中 - How to store a cell value in a variable, delete the same cell value and then paste it in another workbook 如何从另一个工作簿复制一系列单元格并将其粘贴到另一个工作簿? - How to copy a range of cell from another workbook and paste it to another one? 将多个工作簿中的值复制并粘贴到另一个工作簿中的工作表中/在循环中粘贴值 - Copy and Paste VALUES from multiple workbooks to a worksheet in another workbook / Paste Value within Loop 如何从另一个工作表复制图片并粘贴到单元格注释中 - How to copy a picture from another worksheet and paste inside a cell comment VBA:将数据从源工作簿复制并粘贴到目标工作表如果它们的单元格“A1”值彼此相等 - VBA: Copy & Paste data from source workbook to destination worksheet If their Cell "A1" value is equal to each others 复制一个工作表并将其放置在所有其他工作表之后,并将其重命名为同一工作簿中另一个工作表中的单元格引用 - Copy a Worksheet and Place it after all other worksheets and rename it as cell reference in another worksheet in the same workbook
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM