我需要帮助创建一段代码。
答案 0 :(得分:1)
此代码适用于我。请注意评论。
Sub copyA2B()
Dim wb As Workbook
Dim wbSrc As String
Dim cel As Range
'assuming you don't know the source workbook name, looping through the workbooks, otherwise no loop needed
For Each wb In Workbooks
If wb.Name <> ActiveWorkbook.Name Then
wbSrc = wb.Name
Exit For
End If
Next
With Workbooks(wbSrc).ActiveSheet
'assuming the column order is different between the two files, looping through the titles, otherwise no loop needed
For Each cel In .Rows(1).Cells 'assuming the titles are in the first row in both workbooks
If cel <> "" And cel(2) <> "" Then
.Range(cel(2), cel(1).End(xlDown)).Copy Rows(1).Find(cel.Value)(2)
End If
Next
End With
End Sub