Retrieving data between OneDrive files using formula - excel

I'm trying to set up a shared workbook that will collect data from other workbooks onto one sheet. All the files are in the same folder on OneDrive and need to be used by multiple people.
I started by just making a test workbook and opened one of the other workbooks in the same directory as well. Then in the test workbook in one cell I put = and then clicked on a cell from the other workbook and hit enter. This brought through the data from that cell into the test workbook. When I closed the file it converted it into a web address for the file and kept the data. eg:
='http://ourprojects.sharepoint.com/sites/TeamName/FolderName/[Project Name.xlsx]Sheet1'!$A$1
So far so good.
Now the issue is in the main file I need to pull that data from multiple files in the directory that will change as and when projects start/end so I need to build up the formula in parts. So the main web address stays the same, for example "http://ourprojects.sharepoint.com/sites/TeamName/FolderName/" the rest I need to build up depending on what the user fills in.
So ideally I want the user to put in the project name (which will be the same as the workbook name) and the cell they need the data from. Meaning I have 4 things I want to combine:
A1 is Web address = http://ourprojects.sharepoint.com/sites/TeamName/FolderName/
B1 is Workbook Name = Project One
C1 is Sheet Name = Sheet1
D1 is Cell needed = A1
and then in a 5th cell, E1, these are combined to make the filepath to bring in the data:
='http://ourprojects.sharepoint.com/sites/TeamName/FolderName/[Project One.xlsx]Sheet1'!$A$1
I can't for the life of me get this working. I've googled a fair bit and found lots of different answers/solutions from all over including this site but non have worked.
If anyone can help me it would be appreciated.
I did get something kind of working with indirect but obviously that only works with the file open which kind of defeats the aim of this totally. I want this new file to just pull the data in so it gives an overview of everything without having to open them all one by one.

Related

How to dynamically reference to another cell in other workbooks?

i'm trying to create an excel workbook that will automatically collect data from other workbooks in the directory i come up with a code but it does not work correctly
="'"&LEFT(CELL("filename",$A$1),FIND("~",SUBSTITUTE(CELL("filename",$A$1),"[","~",1))-1)&"["&RIGHT(LEFT(CELL("filename",$A$1),FIND("~",SUBSTITUTE(CELL("filename",$A$1),"[","~",1))-2),3)&RIGHT(LEFT(CELL("filename",$A$1),FIND("~",SUBSTITUTE(CELL("filename",$A$1),"[","~",1))+16),1)&".xlsx]Final Data'!"&E3
if i use this code it will call the value of the E3 in the current workbook if i use ADDRESS(3,5) it will give me the right address but the moment i put =INDIRECT() before it, the value of E3(in the current workbook) will come up (the other file is open since i'm using indirect). how can i correct this and is there a way to get ell values while the file is closed ?

Trying to use file path's based on user within a cell formula

I have a spreadsheet with a slew of IF, VLOOKUP, etc formulas with references to data from other worksheets within the same spreadsheets. I will eventually have many of these spreadsheets for each project I am running.
Instead of updating the referenced data in each, I will make one master spreadsheet with the referenced data and the project spreadsheets will reference that master spreadsheet for the data. The problem I have is that other users will use these project spreadsheets and the master spreadsheet will be located on a OneDrive sync'd to the users PC. Now I have to deal with different file paths within the formulas.
I found a VB script that will return the user's PC name. I can build a table that depending on the users name it will point to the right file path. I have tried the file path as a Defined Name but it doesn't work.
This formula works:
=VLOOKUP('CTC Review'!F3&'CTC Review'!G1&'CTC Review'!A13,'C:\Users\user1\OneDrive\Operations\Financials\CTC\CTC Data\[CTC Data Jan-19.xlsx]C2CDataExtractForLabor'!A2:M5000,7)
What I am trying to get to work is:
=VLOOKUP('CTC Review'!F3&'CTC Review'!G1&'CTC Review'!A13,'DEFINEDNAME & C2CDataExtractForLabor'!A2:M5000,7)
Any help would be greatly appreciated.

Load single cell in query in excel

I have n excel files with the same layout, and i want to create a recap file where some info is reported for each file. The info is located in the same specific cells, for example d2 and e2 in every file.
What is the best way to do it? The file names vary without logic and that people that access that file have no skills in coding and macro, so i try to develop something very simple.
I also have no skill in database, but i have managed to create a query with every file in the folder, i have then created a column with the data but i am not able to say that i only want a specific cell, is there a way to do it?
here is a picture of the situation
A formula using INDIRECT can be used, but it will generate a #REF error when the workbook is closed. you could use your macro to open the relevant workbook, and then close it after saving the values
the indirect formula would look something like this:
=INDIRECT("'[Test File.xlxs]Test Data'!$A$7")
or, as a formula using your data:
=INDIRECT("[" & B1 & "]YourSheet!$E$2")

Move sheets containing tables between workbooks without breaking named ranges

-- Edit: this is now part of the bigger question of how to reliably move sheets about --
I've got a workbook which has sheets containing tables and sheet-scoped named ranges. Some of these sheets' formulas link to some of the names on other sheets (i.e. =Sheet1!Sheet1LocalName somewhere on Sheet2).
The time has come for me to create VBA code that moves these sheets into another workbook. Doing so, I of want all existing functionality to remain intact.
When looping over all sheets individually and Worksheet.Move -ing them one at a time to the other workbook, the range name links between the formulas get broken. E.g. when Sheet2 uses a name on Sheet1 in one of it's formulas:
Move over Sheet2;
Sheet2 will still correctly link to Sheet1 back in the source workbook.
Move over Sheet1 itself;
Excel 'helpfully' creates a workbook-scoped name of the same name for me as the name Sheet2 linked to (even if it didn't exist before), where
this new name does point back to the already moved sheet in the destination workbook, after which
the already moved Sheet2's links get modified to point to this new workbook-scope name in the source workbook, thus
messing up the link beyond repair.
Even if I could overcome this by analyzing the formulas beforehand to scan all sheet dependencies, since sheets may have links going both ways between them, it seems I can't do it this way.
When moving all sheets in one go using ThisWorkbook.Worksheets(Array(name1, name2)).Move, I get the Excel error "You cannot copy or move a group of sheets that contain a table".
So it seems I'm sorely out of luck here... There's of course the options of:
moving the sheets individually and rebuilding all formulas afterwards, and
replacing all tables with ranges and rebuilding all tables afterwards
but I'd understandably do not want to go there, since I do not control what goes on the sheets...
Any alternatives?
-- Edit --
The true purpose of this question is that I need to move the sheets over to a temp .xlsx workbook, save/close/re-open that workbook, and then move them back again to the original .xlsm workbook, thus scrubbing them off of their VBA module. See my other SO post for the background, though when I wrote that question I envisioned only needing to scrub the 1 topmost sheet in the ranged-name linking hierarchy, but it turns out I need to do it for all sheets to be safe enough.
After a lot of trial-and-error I found out that moving or copying all sheets in one go just isn't doable because of the tables on them, and handling them one at a time really messes up formulas and named ranges linking them together (even .Copy has similar unwanted side effects to using .Move). While I could in turn write code to 'fix' these broken names or delete these 'helpfully added' rogue names, I wouldn't be surprised if other range linking mechanisms (like chart source, pivot source, data validation list source, form control linked cells, etc.) also acted up badly, making this an even bigger mess to deal with...

Make excel worksheet mirror worksheet in external file

How can I make a worksheet in my excel file mirror exactly the sheet of a different (closed) worksheet.
Basically, I have around 5 files with a lot of data the gets consolidated into a single dashboard with the important information. I then want to create a file (lets call it report) that has the 'main' sheet from each of these different files.
Ideally, the report file will not have to be altered, and when it is opened it will already have all the data needed.
Note: there are merged cells in the documents that are in variable positions.
response to comment #1:
By be there already, for example you can do a vlookup referencing other workbooks.. and the values of those vlookups will be correct when you open the file. First I thought I could just say cell A1 is file 1 = cell A1 in file 2, but the merged cells throw that off because it will not create merged cells to match
I found the following and it can be done in Excel VBA.
1) open consolidated workbook
2) Assuming that all the files you need to consolidate are in a given directory, you can obtain the list of all these files.
2.1) Traverse the list of files and open them one after the other
2.2) When a file is open, you might want to change the name of the sheet before moving it to the "report" file.
2.3) Close each file without saving them.

Resources