Vlookup alternative in vba

rohan85

Board Regular
Joined
Jun 27, 2013
Messages
81
hi, i have data ids in sheet1 in column a i want to lookup the ids in column a in sheet2 from a to e. what can i use apart from vlookup in vba i would appreciate your help please.

sheet1 sheet2

column a column g column a column e

123 ? 123 rr
234 ? 234 tt
567 ? 567 uu


i have the code which i got from internet but could not figure out how to plug in if you could assist please.


Code:
Sub test() 
    Dim a, i As Long 
    a = Sheets("sheet2").Range("a1").CurrentRegion.Resize(, 2).Value 
    With CreateObject("Scripting.Dictionary") 
        For i = 2 To UBound(a, 1) 
            .Item(a(i, 1)) = a(i, 2) 
        Next 
        a = Sheets("sheet1").Range("a1").CurrentRegion.Resize(, 3).Value 
        a(1, 3) = "Supplier Name" 
        For i = 2 To UBound(a, 1) 
            If .exists(a(i, 2)) Then a(i, 3) = .Item(a(i, 2)) 
        Next 
    End With 
    Sheets("sheet1").Range("a1").CurrentRegion.Resize(, 3).Value = a 
End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,215,242
Messages
6,123,830
Members
449,127
Latest member
Cyko

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top