[英]VBA codes for Excel- Find a cells value in another workbook and copy adjacent cell to the first workbook
I have a quick question; 我有一个快速的问题; I have two workbooks, let's say wbk1 and wbk2;
我有两个工作簿,分别是wbk1和wbk2; What I am trying to do is finding each cell value of a column in wbk1 in a specific column of wbk2 and return offset cell value from wbk2 to adjacent cell of the searched value in wbk1.
我想做的是在wbk2的特定列中找到wbk1中一列的每个像元值,并将偏移量像元值从wbk2返回到wbk1中搜索值的相邻像元。
Is there any one who can help? 有谁可以帮忙吗? By the way, I could find following code if it helps;
顺便说一下,如果有帮助,我可以找到以下代码; '=================
“=================
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
'=========================================================================
But It does not work and I can't figure it out. 但这行不通,我无法弄清楚。 I appreciate any comments on this macro.
感谢您对此宏的任何评论。
Cheers 干杯
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.