Professional Excel development

Vlookup using vba

leave a comment »

Rather than clog your workbook with VLOOKUP functions, you can perform the same task through vba. Unlike the VLOOKUP function, there is no need to have the data in ascending order.

This example looks for the value cell $A$1 from “Sculpt” worksheet, returning the corresponding value in the 2nd column of a range in the “Range” worksheet. The value is returned in the form of function and can be retrieved from other subs.


Public Function Vlookup() As Long

Dim x As Integer
Dim strLookup As String
x = 1
strLookup = Worksheets(“Sculpt”).Range(“$A$1:$A$1”)
Do Until Worksheets(“Range”).Cells(x, 1).Value = “”
If Worksheets(“Range”).Cells(x, 1).Value = strLookup Then
Vlookup = Worksheets(“Range”).Cells(x, 2).Value
Exit Do ‘if value is found, the code stops searching
End If
x = x + 1

End Function


Written by Austin

January 2, 2007 at 4:30 pm

Posted in do until, functions, vba, vlookup

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: