简体   繁体   English

如何根据列的值粘贴到一行

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

相关问题 如何将列宽和表格设置粘贴到根据原始工作簿中的唯一值创建的新工作簿 - how do i paste column widths and table settings to new workbook which is created based off of a unique value in original workbook 不要粘贴整个列,只粘贴基于 x 值的行 - Don't paste entire Column, only row based on x value Excel / VB-如何遍历每个行/列,并根据值进行格式化? - Excel / VB - How do I loop through each row/column and do formatting based on the value? 如何根据列和行的选择从Excel表中选择特定值? - How do I select specific value from Excel table based on a column and row selection? 如何根据列行数据复制粘贴到文本文件中并保存 - How to Copy and Paste Into Text File and Save Based on Column Row Data 如何根据 Excel 中的空白列从行中剪切和粘贴值? - How to cut and paste values from a row based on Blank column in Excel? 如何根据该行中的单元格值复制特定行并将其粘贴到匹配的工作表 - How can I copy specific rows based on a cell value in that row and paste it to a matching worksheet 我如何遍历一列,如果单元格符合某些条件,则将整行粘贴到另一个工作表中 - How do I loop through a column, if a cell matches some criteria then paste that whole row into another worksheet 根据单元格中的行号值粘贴到行 - Paste to row based on row number value in cell 如何根据条件复制基于行值的粘贴数据 - How to copy paste data based on row value with conditions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM