Forum Discussion
INDEX MATCH with multiple spreadsheets
Unfortunately your description is not adequate to fully appreciate the actual details of how. your workbooks are organized. Is it possible for you to post the actual spreadsheets (not an image; the actual spreadsheets) OR, if they contain proprietary or private information, post a mockup that represents the reality.
INDIRECT may well be a part of the solution, but without seeing more specifics it's hard to tell. If you wish to pursue your own solution more, here's a reference that may help. https://exceljet.net/excel-functions/excel-indirect-function
- milanvi1Aug 23, 2021Copper Contributor
Hi Mathetes
Many thanks for getting back. I am attaching both Excel files. My goal is to populate in Excel file A the cells B5 to B10 with the values that correspond to the account numbers from Excel file B. My original file has more than 50 spreadsheets each for a different project. Instead of using a separate formula for each spreadsheet linking it to the relevant spreadsheet (and same project) in Excel file B I was wondering if the formula can be flexible as to have the name of the spreadsheet defined through cell A1. Hope this makes sense! Many thanks!!
- mathetesAug 23, 2021Silver Contributor
In the attached revisions to your files are three examples of how INDIRECT could be used.
For Project 1, I chose the simplest.
=INDIRECT($A$1&A5)
Here is an image of the screen with that formula showing in cell C5; the formula is just copied down the rest of column C. $A$1 is the cell containing the reference to the other file and the appropriate tab; A5 refers to the cell in that tab. INDIRECT contains those two references and the concatenation operator (&) which puts them together as a complete reference.
For project 2 I use INDIRECT within a VLOOKUP, again in cell C5 and copied down.
=VLOOKUP(B5,INDIRECT($A$1),2,0)
In this case, cell $A$1 contains a reference to the file and tab, but also a reference to a "named range" in File B. I assigned a name--"Proj2Bud"--to the range of cells that contains the account number and associated cash balances. So here's a screen capture of what that looks like.
For Project 3 I used INDEX and MATCH and nested INDIRECT in each, using two different cells as references, one in connection with INDEX and the other in connection with MATCH. This is the more complicated, obviously. And this uses two named ranges, one for account numbers, the other for the cash balances.
=INDEX(INDIRECT($A$2),MATCH(B5,INDIRECT($A$1),0))
It looks like this:
I'm attaching revised versions of both your files, so you can play around with the various methods. I want to add a couple of "however" though... this is meant to show how INDIRECT works, and might work for you.
HOWEVER #1, the source file for these--your "Excel File B"--is conveniently laid out so that B9 through B14 contain the balances in the associated account numbers. This makes it easy for each of the different approaches to work. In your real world is that the case?
HOWEVER #2, and it's a big however, from the description you've given, I wonder if there aren't other changes I'd want to make if I were in your shoes, or if we were sitting down face to face. The fact that you have 50 spreadsheets for different projects raises flags in my mind. That may be legitimate--there may indeed be compelling reasons to have one sheet per project--but it may also be just because it's easier for humans to comprehend. When working with a database (in this case, that's what we're doing), Excel can do wonders if data regarding all comparable items (e.g., projects) are stored in a single table, from which it can extract project specific data quite readily. By "manually" separating them into individual sheets--unless they're distinct in multiple ways, using categorically different types of data--we sometimes inadvertently (for all the best motives) make it harder to get summary inclusive reports.
So I offer that as backdrop to these starter questions:
- Why do you have one sheet per project?
- How different are they?
- Could all the data on each project be combined into a single database, with a single column denoting which project a given item represents?
- Would it be possible in your real world files to have both workbooks combined? They'd still be able to use INDIRECT to refer to different tabs, but would not have to go through the potential volatile combination of incorporating a different filename as part of that connection.
- milanvi1Aug 23, 2021Copper ContributorThanks so much for you extensive answer and the points you are highlighting.
To your first however, yes it would be the case that the layout for the accounts would be the same.
Perhaps some background on the files. Excel file B would be delivered on a monthly basis therefore containing the figure only for that particular month. It needs to be in such a format as it is reviewed by multiple parties. My idea is to build a database with Excel file A where all the data on each project is stored as a time line. I would then be able to create different output sheets which can compare individual projects or subset projects across time. My issue is that Excel B arrives every month and need to import it somehow into the master file Excel A. Of course I could just copy it with 50 times. But I am trying to work out an easier way. Of course open to other suggestions should you have.
Also, I noticed that in Excel A in cell A1 and B1 you typed in the file name. If I wanted to only have the name of the spreadsheet e.g. Project 3 in that cell and within the Indirect/Match formula the path just using that part of the name from the cell A1, how would I code that?
Many thanks!