我有一个简单的问题;我有两本工作簿,让我们说wbk1和wbk2;我想要做的是在wbk2的特定列中找到wbk1中列的每个单元格值,并将wbk2中的偏移单元格值返回到wbk1中搜索值的相邻单元格。
有谁可以提供帮助? 顺便说一句,如果它有帮助,我可以找到以下代码; ' =================
Sub find1()
Dim Key
Dim Target
Dim Hnum
Dim Success
Dim wbk As Workbook
Dim Lastrow As Long
Dim one As Long
Success = False
Application.ScreenUpdating = False
strSecondFile = "C:\Soroush\08- Technical\03- Stock\Test\PL_Test_01\PL_Test_01.xlsm"
strFrthFile = "C:\Soroush\08- Technical\03- Stock\CNC_Test.xlsx"
'==
Sheets("sheet2").Select
Lastrow = ActiveSheet.UsedRange.Rows.Count
If Not IsEmpty(Cells(5, 9).Value) Then
Key = Cells(5, 9).Value
For i = 5 To Lastrow
' If Not IsEmpty(Cells(i, 9).Value) Then
' Key = Cells(i, 9).Value
Set wbk = Workbooks.Open(strFrthFile)
With wbk.Sheets("Sheet1")
Set Target = Columns(1).find(Key, LookIn:=xlValues)
If Not Target Is Nothing Then
ActiveCell.Select
Selection.Copy
Set wbk = Workbooks.Open(strSecondFile)
With wbk.Sheets("Sheet2")
Sheets("Sheet2").Select
Cells(i, 10).Select
ActiveCell.Paste
If Not IsEmpty(Cells(i + 1, 9).Value) Then
Key = Cells(i + 1, 9).Value
End If
End With
End If
End With
'End If
Next
End If
End Sub
'=========================================================================
但它没有用,我无法弄明白。我感谢对这个宏的任何评论。
干杯