[英]How do I paste into a row based on the value of a column
It may be already on here and Ive missed it but I'm having trouble working out how to change my code from pasting into the last row to pasting into a specific row. 它可能已经在这里,我错过了它,但我无法弄清楚如何将我的代码从粘贴更改为最后一行到粘贴到特定行。
Each dataset has a unique number in column A. I need to paste the Array into the row which matches the unique reference on the data entry Sheet. 每个数据集在A列中都有一个唯一的编号。我需要将Array粘贴到与数据条目表上的唯一引用匹配的行中。
So if the data entry sheet (Enter Action), has "123" in cell C3, I need it to look at the database (RAW DATA) and find the row with "123" in Column A and paste the Array into this row. 因此,如果数据条目表(Enter Action)在单元格C3中有“123”,我需要它来查看数据库(RAW DATA)并在A列中找到带有“123”的行并将Array粘贴到此行中。
I have only ever pasted into the last row before and don't know how to change the below code to do what I need. 我以前只粘贴到最后一行,不知道如何更改下面的代码来做我需要的。
Dim vCopy, i As Long, rPaste As Range
vCopy = Array("C3", "C5", "Q26", "C7", "C9", "Q26", "C11", "C13", "C15", "G13", "G3", "C17", "G7", "G9", "K3", "G11", "K9")
Set rPaste = Sheets("RAW DATA").Cells(Rows.count, 1).End(xlUp)(2)
For i = LBound(vCopy) To UBound(vCopy)
rPaste.Value = Sheets("Enter Action").Range(vCopy(i)).Value
Set rPaste = rPaste.Offset(, 1)
Next i
You can use Find
: 您可以使用
Find
:
Dim vCopy, i As Long, f As Range, lookFor
vCopy = Array("C3", "C5", "Q26", "C7", "C9", "Q26", "C11", "C13", "C15", _
"G13", "G3", "C17", "G7", "G9", "K3", "G11", "K9")
lookFor = Sheets("Enter Action").range("c3").value
Set f = Sheets("RAW DATA").Columns(1).find(lookFor, lookat:=xlWhole)
If not f is nothing then
For i = LBound(vCopy) To UBound(vCopy)
f.Offset(0, i).Value = Sheets("Enter Action").Range(vCopy(i)).Value 'fixed#2
Next i
End If
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.