how to make VlookUp on VBA excel?

Hello Experts!

I am new to VBA and still exploring.
I want to make a macro in which if the user will click a button it will let the user to input all the attributes for VlookUp and then the macro will search the VLookUp value and paste it to the active cell.

Thank you in advance!
NewBieSteffieInternAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
how to make VlookUp on VBA excel?
try use:

Application.WorksheetFunction.VLookup

Open in new window

0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You may give this a try...
Sub VLookup()
Dim cell As Range, LookupCell As Range, LookupRange As Range, Target As Range
Dim ColIndex As Integer
Set cell = ActiveCell
On Error Resume Next

Set LookupCell = Application.InputBox("Select cell with Lookup value.", Type:=8)
If LookupCell Is Nothing Then
    MsgBox "You didn't select the cell with Lookup value.", vbExclamation
    Exit Sub
End If

Set LookupRange = Application.InputBox("Select Lookup Table Range.", Type:=8)
If LookupRange Is Nothing Then
    MsgBox "You didn't select the Lookup Range.", vbExclamation
    Exit Sub
End If

ColIndex = Application.InputBox("Please specify the column index from the Lookup Range " & LookupRange.Address(0, 0), Type:=1)
If ColIndex = 0 Then
    MsgBox "You didn't specify the Column Index.", vbExclamation
    Exit Sub
End If

Set Target = LookupRange.Columns(1).Find(what:=LookupCell.Value, lookat:=xlWhole)

If Not Target Is Nothing Then
    cell.Value = Target.Offset(0, ColIndex - 1).Value
Else
    MsgBox "The Lookup value " & LookupCell.Value & " was not found in the range " & LookupRange.Columns(1).Address & ".", vbExclamation
End If
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NewBieSteffieInternAuthor Commented:
Thank you for this.

It worked!!!
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.