Hello Friends,
I am trying to vlookup on two range,
if Name not found in single range then check in second range,
if not found in there also then I want result not found.
Below is my attempted code.
<tbody>
</tbody>
I am trying to vlookup on two range,
if Name not found in single range then check in second range,
if not found in there also then I want result not found.
Below is my attempted code.
A | B | D | E | G | H | ||
Name | Score | Name | Match Score | Name | Match Score | ||
Sachin | 105 | Sachin | 105 | Dhoni | 98 | ||
Dhoni | 98 | Dhoni | 98 | Bravo | 35 | ||
Virat | Not Found | Bravo | 35 | Ponting | 75 | ||
Virender | Not Found | Ponting | 75 | Brett Lee | 20 | ||
Brett Lee | 20 | Brett Lee | 20 | Sachin | 105 | ||
Bravo | 35 | Yuvaraj | 111 | ||||
Kapil Dev | Not Found |
<tbody>
</tbody>
Code:
Sub Double_Error()
Dim lr As Long, r As Long
Dim myrange1 As Range
Dim myrange2 As Range
Set myrange1 = Sheet1.Range("D:E")
Set myrange2 = Sheet1.Range("G:H")
lr = Sheet1.Range("a500").End(xlUp).Row
Sheet1.Activate
On Error GoTo Error1
For r = 2 To lr
Cells(r, 2).Value = WorksheetFunction.VLookup(Cells(r, 1), myrange1, 2, False)
Next r
Exit Sub
Error1:
On Error GoTo Error2
Cells(r, 2).Value = WorksheetFunction.VLookup(Cells(r, 1), myrange2, 2, False)
Resume Next
Error2:
Cells(r, 2).Value = "Not Found"
Resume Next
End Sub
Last edited by a moderator: