Excel VLOOKUP based on Cell

HNarli

New Member
Joined
Jun 26, 2018
Messages
24
Hello,

I am trying to do a lookup based on a variable file name which I'd like to fetch from cell I2. I am very new to complex excel formula so am hoping someone can tell me exactly what I need to do to make this work! I've tried looking around other peoples posts on this and adapt it but get back #REF ! every time :-( I think I am missing something so if someone could please just type the exact string for me I'd be so grateful! I'm not being lazy, I literally cannot get my head around it, so hoping if I can see it I can understand how to do this...

So, to explain.

I am trying to say look up the discount amount of a supplier based a file for each supplier I have called Supplier_Disc file which can be found: A:\Marketing\Templates (Do Not Move or Delete)\Database\Files

The file name is Supplier_Discount_XXXXX.xlsx

The file path does not change, only the supplier name 'XXXX' in blue which I have stored in cell I2.

Not sure if this is right but in cell I2 i've concatenated the words "Supplier_Discount" &B2 (which in B2 is the supplier name only).

So to clarify

Here is what I have tried so far in case it sheds some light on what I am trying to achieve, but I'm aware I've got it wrong!

=VLOOKUP($D$2,INDIRECT("'A:\Marketing\Templates (Do Not Move or Delete)\Database\Files\["&I2&".xlsx]Sheet1!$A$1:$P$500"),1,0)

Kind regards,
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Try

Code:
=VLOOKUP($D$2,INDIRECT("'A:\Marketing\Templates (Do Not Move or Delete)\Database\Files\["&I2&".xlsx]Sheet1'!$A$1:$P$500"),1,0)

When using indirect you may find it helpful make the formula without the indirect first so you can see reference you need to create in the indirect.

Code:
=VLOOKUP(D2,'A:\marketing\Templates (Do Not Move or Delete)\Database\Files\[Supplier_Discount_XXXXX.xlsx]Sheet1'!$A$1:$P$500,1,0)

Note Indirect does not like closed workbooks. Make sure all the Supplier_Discount files are open.
 
Upvote 0
Upvote 0
Hi mrmmickle1, thanks for the quick reply. Shame to hear this as VBA scares me :-( I was kinda hoping this one string of formula was going to solve this for me but if I can't work out the VLOOKUP I know I won't understand the VBA.
I've had a read through of your links but I cant see that they cover Vlookup within the file once it's opened. For example I sort of follow the stackoverflow link about looking in a specific cell of the open document... but I am trying to vlook up a cell based on the selected supplier name once it's open. If anyone can please help me with further explaining this or making it a bit clearer based on my scenario that would be great :-)

Thanks
 
Upvote 0
Here's a reference on how to use VBA code:

https://www.ablebits.com/office-addins-blog/2013/12/06/add-run-vba-macro-excel/

You can open a workbook and use it in a vlookup like this:

Code:
Sub AccessData()
    
    Dim DestWkBk As Workbook
    Dim SrcWkBk As Workbook
    Dim myResult As Variant
    
    Set SrcWkBk = ThisWorkbook 'This is the workbook with the value you are trying to look up
    Set DestWkBk = Workbooks.Open(Filename:="file location") 'This is the workbook of the vlookup table


    myResult = Application.VLookup(SrcWkBk.Sheets("YourWorksheet").Range("A1"), DestWkBk.Sheets("YourTableRange").Range("$A$2:$B$30"), 2, False)
    DestWkBk.Close SaveChanges:=False 'Close workbook and do not save any changes
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,250
Members
452,623
Latest member
Techenthusiast

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