[英]How to copy and paste a range to another worksheet by matching a cell value
[英]How to copy and paste a cell value to another worksheet in the same workbook
目前,我正在制作一個需要執行以下操作的宏。
1)通過第一行查找,返回一個命名列
2)然后選擇此列
3)然后,它遍歷列以查找第一個大於零的值。
4)然后我取這個“第一個”實例的行值
5)從我的公共變量中,我得到一個列值(#)
6)我結合行值和列值來找到我的“數據點”
最后,我想將此值復制到同一工作簿中名為“關鍵信號”的另一個工作表中
這是我遇到麻煩的地方。 每次運行代碼時,都會出現錯誤“ 1004”。 我似乎無法將所選單元格復制並粘貼到第二個工作表中。 有任何想法嗎?
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
您已接近,只需從此行中刪除Range
:
Sheets(1).Range(Cells(CritRow, Trip_point)).Copy
這樣看起來像這樣:
Sheets(1).Cells(CritRow, Trip_point).Copy
另外,我建議不要使用Active
或Select
語句。 例如,您要復制和粘貼的4行代碼可能看起來像這樣:
Sheets("Critical Signals").Range("E4") = Sheets(1).Cells(CritRow, Trip_point)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.