Importing data from a different spreadsheet - excel

I'm familiar with using the following to pull data in from another spreadsheet....
=[filename.xlsm]Sheet!A1
My question is, can I specify the filename in a cell (like AI) then use that cell reference in order to pull that data in...
A1 = filename.xlsm
Then the corresponding cell formula would be
=[AI]Sheet!A1
Such that if I changed the name of the file in cell A1 I would change the reference and pull data from another source? The above is just an example, it doesn't work so my question is can this be done and if so, how?
** The file that I am pulling data from may not be open at the same time **
Many thanks.

Yep! Using Indirect() you can:
If A1 has a filename, in B1 you can put:
=Indirect("'["&A1&"]Sheet1'!A1")
Note: With Indirect(), your workbook that you're referring to has to be open, otherwise you'll see an #REF error.

Related

Insert filename into directory link from cell value

I've got a list of 150 filenames in column A e.g. WorkBook1-WorkBook150 and want to reference this when including the file directory so I will be able to reference a cell out of the workbook. The cell is an outstanding amount for a particular supplier so I wish to create a workbook to have a full overview of the outstanding amount and broken down for each supplier in a list.
A1 filename: File1.xls
So if filename 1 is in A1, is there a way to action this so we can pull the filename from A1 and insert it in the relevant place in the directory? It works if I input the text from A1 manually but referencing the cell into the relevant place would save a lot of time.
Example of what I wish to input in B1: ='C:\Directory\FolderName[A1]Sheet1'!$D$4
Thank you for your time!
If I understand your question correctly, what you need is the 'CONCATENATE' formula. A1 contains 'filename.xls'. In B1 you can put: 'C:\Directory\FolderName\'
In C1 you can then put
=CONCATENATE(B1;A1)
which gives you
C:\Directory\FolderName\filename.xls
If you are trying to make it where you choose from a list you would need to use the data validation button and make a list. Make sure you have the reference in another cell.
Then you can use concatenate with the drop-down cell for efficiency.

Multiple Cell Vlookup Searches

I trying to make this formula flexible so I can search the value in a cell in multiple file paths and different excel files to give me a result.
My data in each excel fiel is in the same table for each workbook.
=VLOOKUP(A6,IndirectEx("'C:\_Excel\ExcelExamples\VLOOKUP_External_Sample\[Workbookname.xlsx]Master'!MatlDB"),1,0)
Can you guys help.
Thanks-
Based on your comment that the file paths are stored in a table, and assuming that these are on a sheet named "Locations":
=VLOOKUP(A6,INDIRECT(Locations!A1&Locations!B1),1,0)
This should work, but the cell references are hardcoded. Not sure how you want to select the references.
I answered my own question. So after some trial and error my result, and if someone can find a better way or help me create a macro, that would be awesome.
="vlookup(A1,"&"'"&""&A2&"\"&"["&A3&"]"&"SampleTab'!$G$62:$DU$175,A4,0)"
So what I had to do is write it as I was creating a text. Copied it into a different cell and remove the quotations from the formula.
Then move the range P114 , C117 , C122 & Q113
A1 would be the lookup value cell.
A2 would be the file path cell.
A3 would be the workbook name (note it has to include the file extension)
The range (SampleTab'!$G$62:$DU$175) has to be hard coded for now. A4 would be the row where the data is at.

Referencing closed workbook to get cell values

I have searched the site but could not find a satisfactory answer.
I have the path of the directory in Cell A1 = C:\Sundeep\
I have the file name in Cell B1 = ibm
I want the value of cell C6 on sheet data in the file
C:\Sundeep[ibm.xlsm]data!C6
and want to put it in cell C1 in the current workbook. I don't want to use vba code and I don't want to use indirect (as that requires the ibm.xlsm to be open).
If I put this string in C1 (hardcoded), then it works
='C:\sundeep[ibm.xlsm]data'!$C$6
However, if I try something like this
=CONCATENATE("'",A1,"[",B1,".xlsm]data'!")$c$6
it does not work.
Any help is appreciated.
You cannot use the cell value to be redirected to a workbook since even using Indirect() with the closed workbook will also fail.
You have to use Indirect.Ext() function of Morefunc add-in.

Indirect function with file path

I am trying to create a formula that will look at four cells and return the contents of a cell defined by the contents of the 4 ref cells. for example:
a1 - file path
a2 - workbook name
a3 - sheet name
a4 - cell ref
I've tried to concantenate the cells to produce the full cell address to use in the indirect fucntion and also tried to 'build' the full address within the indirect function, either way I get a #ref!
I have tried to evaluate the formula and it looks fine as I step through building the file path but on the very last step goes to #ref!
Any advice that anyone can offer is greatly appreciated - Thanks
Indirect() does not work with external files, unless they are open in the same instance of Excel.
A free add-in called "morefunc.xll", which you can download here, contains a function called Indirect.Ext which DOES work with external closed files.
This add-in does not work with 64 bit Excel, though, but if you are using 32bit Excel you will be able to use it.

Use Cell Value as reference for VLOOKUP table array?

I would like to be able to allow a user to change the file being used as a reference in a VLOOKUP. All the files being used will have the same array, just different files paths.
This is how i think it should operate.
Click macro button that opens file browser.
Allow user to choose file.
Paste file path in cell (A1)
Convert path to include array.
In VLOOKUP formula, reference the cell A1 as the 'table array'.
I am already able to complete up to step 3. Any idea on how to add the defined array and reference the cell in a VLOOKUP?
I would just record doing exactly what you want to do and then replace what you did with a variable that gets assigned, like when you place the path into cell A1. Then just have the macro re-write the appropriate vlookup formula.
You could also make a formula that would show what you want, and then use vba to copy that and paste values. You may then need to find and replace something in the cell(s) to get it to actually convert to a formula.
Example:
In A1 Put the path (with workbook name, i.e.C:\Users\username\Desktop\Book3.xlsx )
In B1 ="=VLOOKUP(D1,'"&MID(A5,1,FIND("*",SUBSTITUTE(A5,"\","*",LEN(A5)-LEN(SUBSTITUTE(A5,"\","")))))&"["&MID(A5,FIND("*",SUBSTITUTE(A5,"\","*",LEN(A5)-LEN(SUBSTITUTE(A5,"\",""))))+1,100)&"]Sheet1'!B$1:C$4,2,FALSE)"
B1 then looks like this =VLOOKUP(D1,'C:\Users\username\Desktop\[Book3.xlsx]Sheet1'!B$1:C$4,2,FALSE)
Copy B1 to C1 and do a find replace of something, like find Users and replace all with Users.
This is messy, but I use something like this for a tool that needs to update form 30 different files of different sizes based on 6000 rows of array formulas that update of yet another spreadsheet. It works well for me, but a bit slow for large files.

Resources