-1

我正在尝试开发代码来执行以下操作:

1)Copy cells K4: M4 in Workbook 1, Sheet 1 <- I can do this step;

2)Find a cell in Workbook2, Sheet1, column C that matches cell B4 in
Workbook1, Sheet1;

3)Paste the copied values in columns P:R of the matching row in
Workbook 2, Sheet 1 as determined in Step 2.

对于无法将我自己的工作推进到第 1 步之外,我提前道歉。正如我所说,我对此完全陌生,并且在此之前一直在网上搜索答案/学习,但没有找到解决方案。

4

1 回答 1

1

我对此进行了测试,并且有效。这有助于您入门吗?

Sub CopyToMatchedRow()
    Dim copyRng As Range, matchVal As Variant, matchRng As Range, matchRow As Integer

    Set copyRng = Worksheets("Sheet1").Range("K4:M4")
    Set matchRng = Worksheets("Sheet2").Range("C:C")
    matchVal = Worksheets("Sheet1").Range("B4")
    matchRow = matchRng.Find(What:=matchVal, After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)

    copyRng.Copy Destination:=Worksheets("Sheet2").Range("P" & matchRow & ":R" & matchRow)
End Sub
于 2013-03-15T19:41:02.440 回答