Vlookup or Index Match (Code)

Seandobson2402

New Member
Joined
Feb 9, 2018
Messages
23
Hi All,

I want to learn how to do a VLOOKUP in VBA. But it seems rather confusing when reading different sites online. I wish to put the following formula into Worksheet "Weekly Stats" Cell "D3" -

=VLOOKUP('Weekly Stats'!A1,'My Stats'!C4:M56,4,FALSE)

1. Worksheets("Weekly Stats") is where the formula needs to go - into cell ("D3")
2. Worksheets("Weekly Stats").Range("A1") is the Value I wish to match in the VLOOKUP
3. Worksheets("My Stats").Range("C4:M56") is the range I wish to match my value to - column ("C") containing the Same data as ("Weekly Stats").Range("A1"), and column ("F") being the fourth column along from C (,4) for the information I wish to display in ("Weekly Stats").Range("D3")
4. I wish the value to be paste special values so no formula will be showing.

Is the above possible?

Thanks
Sean
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
If I understand correctly what you want, this should do it:
Rich (BB code):
With Worksheets("Weekly Stats").Range("D3")
      .Formula = "=VLOOKUP('Weekly Stats'!A1,'My Stats'!C4:M56,4,FALSE)"
      .Value = .Value
End With

 
Upvote 0
Another way is to call VLOOKUP from within VBA:

Code:
    Set ws = Worksheets("Weekly Stats")
    Set ms = Worksheets("My Stats")
    ws.Range("D3").Value = WorksheetFunction.VLookup(ws.Range("A1"), ms.Range("C4:M56"), 4, False)
 
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,301
Members
452,633
Latest member
DougMo

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