I keep getting a Run-time error ‘13’: Type mismatch when running the following code. The error only occurs at this line:
.Cells(i, 119).Value = IIf(IsError(LN), "", LN & ", " & FN)
The code is looking for a value in the wkbData sheet. If the value is not found, it returns “”. The code runs fine if the lookup value is in the wkbData sheet. The error pops up for the first instance for which the lookup value is not found on this line. I don’t get the error for the two proceeding lines, so I can’t figure out why it won’t work. Thanks in advance for any comments.
Sub LookupName()
Dim wkbData As Workbook
Dim wkbSrc As Workbook
Dim LastRow As Long
Dim i As Long
Dim LN As Variant
Dim FN As Variant
Set wkbSrc = ThisWorkbook
Set wkbSrc = ActiveWorkbook
Set wkbData = Workbooks.Open("E:\Projects\Householding\Data File - LARS - Agent Info\LARS_Qry_All_Agents.xlsx")
With wsFullFile
LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
For i = 2 To LastRow
LN = Application.VLookup(.Cells(i, 32).Value, wkbData.Worksheets("Qry_All_Agents").Range("B:D"), 2, False)
FN = Application.VLookup(.Cells(i, 32).Value, wkbData.Worksheets("Qry_All_Agents").Range("B:D"), 3, False)
.Cells(i, 117).Value = IIf(IsError(LN), "", LN)
.Cells(i, 118).Value = IIf(IsError(FN), "", FN)
.Cells(i, 119).Value = IIf(IsError(LN), "", LN & ", " & FN)
Next i
End With
wkbData.Close SaveChanges:=False
End Sub
Bookmarks