I am trying to find the details from two columns based on the text string in a third column from two separate excel files
The code should search file B column C for a match as listed in column A from the code sheet (file A).
When it finds a matching word, it then copies details from file B, column D at the correct row into file A column B and also column F to column C (file B to file A).
It works for finding the first string, but if there is more than one entry of the same name in file B, it fails. (there is only one instance of the same name).
If VBA.Dir(textFile) = "" Then
MsgBox "File " & textFile & " doesn't exist."
End
End If
Set objFSO = CreateObject("Scripting.FileSystemObject")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error Resume Next
Workbooks(objFSO.GetBaseName(textFile)).Close SaveChanges:=False
Workbooks.Open Filename:=textFile
On Error GoTo 0
textFileName = ActiveWorkbook.Name
Workbooks(origFileName).Activate
Set objRange = Columns("A")
lLastRow = objRange.Cells(Rows.Count).End(xlUp).Row
For iloop = 2 To lLastRow
Workbooks(origFileName).Activate
searchString = ActiveSheet.Cells(iloop, 1)
fgetRowNumber = 0
If searchString <> "" Then
Workbooks(textFileName).Activate
If Right$(partName, 1) = "D" Then
On Error Resume Next
fgetRowNumber = ActiveSheet.Cells(1, 3).EntireColumn.Find(What:=searchString, SearchOrder:=xlByRows, SearchDirection:=xlDown, MatchCase:=False).Row
Set fgetRowNumber = ActiveSheet.Columns(3).FindNext(fgetRowNumber)
On Error GoTo 0
Else
On Error Resume Next
fgetRowNumber = ActiveSheet.Cells(1, 3).EntireColumn.Find(What:=searchString, SearchOrder:=xlByRows, SearchDirection:=xlDown, MatchCase:=False).Row
On Error GoTo 0
End If
If fgetRowNumber > 0 Then
partName = ActiveSheet.Cells(fgetRowNumber, 4)
partRev = ActiveSheet.Cells(fgetRowNumber, 6)
Workbooks(origFileName).Activate
ActiveSheet.Cells(iloop, 2) = partName
ActiveSheet.Cells(iloop, 3) = partRev
Else
Workbooks(origFileName).Activate
ActiveSheet.Cells(iloop, 2) = ""
ActiveSheet.Cells(iloop, 3) = ""
End If
End If
Next
On Error Resume Next
Workbooks(textFileName).Close SaveChanges:=False
On Error GoTo 0
Workbooks(origFileName).Activate
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Bookmarks