Hi thewhawk,
Notes:- i renamed the files as Test1 and Test2.
- i renamed worksheets as "Sheet1" in both the files.
- the code is to be run from Test1 workbook.
Try this modified code:
Sub Copy_Email_Info()
Dim Wb1 As Workbook, Wb2 As Workbook, i As Integer
Dim sEmail1 As String, sEmail2 As Variant
Application.ScreenUpdating = False
Set Wb1 = ThisWorkbook
Set Wb2 = Workbooks.Open(Filename:="C:\Example\Test2.xlsx") ' Change "C:\Example\Test2.xlsx" to actual file path with name & file extension
For i = 2 To 6 Step 1 'change 2 & 6 to the actual number of email addresses in Spreadsheet1
sEmail1 = ThisWorkbook.Worksheets("Sheet1").Range("A" & i)
With Wb2.Worksheets("Sheet1")
sEmail2 = Application.VLookup(sEmail1, .Range("A1:B5"), 2, False)
End With
If IsError(sEmail2) Then
ThisWorkbook.Worksheets("Sheet1").Range("F" & i) = "Email not found in Test2"
Else
ThisWorkbook.Worksheets("Sheet1").Range("F" & i) = sEmail2
End If
Next i
Wb2.Close
Set Wb1 = Nothing
Set Wb2 = Nothing
Application.ScreenUpdating = True
End Sub
This works fine when I tested. Let me know if this worked for you.
Warm regards,
Jewel
Bookmarks