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!
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!