p45cal, I would write the second code a little differently. First, I would check if X or Y (or both) contain an error. Then, Select Case performed only when there is no error.
Do While Cells(i, 1).Value <> ""
With Application
x = .VLookup(sht1.Cells(i, 1), sht2.Range("A:H"), 7, 0)
y = .VLookup(sht1.Cells(i, 1), sht2.Range("A:H"), 8, 0)
End With
If Not IsError(x) Then
Select Case True
Case x = 2 And y = 1: Cells(i, 5) = "T+1"
Case x = 0 And y = 0: Cells(i, 5) = "T+0"
Case x = 1 And y = 1: Cells(i, 5) = "T-1"
Case x = 1 And y = 2: Cells(i, 5) = "T-2"
Case x = 1 And y = 3: Cells(i, 5) = "T-3"
End Select
End If
i = i + 1
Loop
noob93, You must know that there is a difference in error handling (when the sheet function returns an error), depending on the context in which you call this function.
If it do not find the result:
- Application.WorksheetFunction.VLookup creates a runtime error,
- Application.VLookup returns a sheet error (e.g., #N/A!)
I think Charles Pearson will explain it enough http://www.cpearson.com/Excel/Callin...ionsInVBA.aspx
Artik