Vlookup probelm

N

NewToVB

I'm doing a vlookup to find the matching identifier in another excel sheet,
and when it doesn't find the matching identifier, then look for another
identifier in the sheet, if neither are there return a zero. But for some
reason, when it doesn't find the first identifier it doesn't look for the
other, it just returns zero, any idea why?
This is what I have:

For i = 3 To lastRow Step 1
tmp = VariantType.Empty

On Error Resume Next
tmp = LCV.WorksheetFunction.VLookup(LCV.Range("A" & i).Value,
oApp.Range("A1:J" & lastRow2).Value, 10, False)
On Error GoTo 0

If tmp = VariantType.Empty Then
On Error Resume Next
tmp = LCV.WorksheetFunction.VLookup(LCV.Range("B" &
i).Value, oApp.Range("B1:J" & lastRow2).Value, 10, False)
On Error GoTo 0
If tmp = VariantType.Empty Then
LCV.Range("L" & i).Value = 0
Else : LCV.Range("L" & i).Value = tmp
End If
Else : LCV.Range("L" & i).Value = tmp
End If
Next i

Thanks in advance!
 
D

Don Guillett

Life will be a lot easier if you try looking in the vba help index for
FINDNEXT. Good example.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top