BIGMOOSE88
New Member
- Joined
- Jun 3, 2010
- Messages
- 13
Is there anyway when doing vlookup through VBA to include the sourcelist (Ranges) in the VBA code itself without having to put any information in the sheet?
I found this code by Benvolio in the Mr Excel Message Board Archive:
I found this code by Benvolio in the Mr Excel Message Board Archive:
Code:
Sub Example_of_Vlookup()
Dim lookFor As Range
Dim rng As Range
Dim col As Integer
Dim found As Variant
Set lookFor = Sheets("Sheet2").Range("A1")
Set rng = Sheets("Sheet1").Columns("A:C")
col = 3
On Error Resume Next
found = Application.Vlookup(lookFor.Value, rng, col, 0)
If IsError(found) Then
MsgBox lookFor & " not found"
Else: MsgBox "The look-up value of " & lookFor & " is " & found & " in column " & col
End If
On Error GoTo 0
End Sub