I would like to set up Names for the drive, file path, Excel spreadsheet name and sheet name in cells in Excel, and then concatenate them together when referencing external cells. This will allow me to create macros that reference sheets dynamically in the sense that it does not matter where the spreadsheet is.
So far, I have the following:
Drive = C
Location = Users\ashleys\Desktop\New Quote Production\Quote Location 3\Ash
Name = Book3
Sheet = Sheet1
(Please note that the = sign above can be read as "assigned Name as")
I concatenate these together to create another Name (called Final) in the following fashion:
Final = "'"&Drive&":\"&Location&"["&Name&".xlsx]"&Sheet&"'!"
Final resolves to be the following:
C:\Users\ashleys\Desktop\New Quote Production\Quote Location 3\Ash\[Book3.xlsx]Sheet1'!
So, as far as I am concerned, so far so good!
However, I am embarrassingly stumbling at the last hurdle. when I use the Final defined Name in cell references, it does not resolve in the way I expect. So, if I am in Book1 and I use the code above to refer to cell A3 (which for example contains the word "Success!") in Book3, I would hope that typing the following into a cell in Book1 would resolve to "Success!":
=Full&A3
Instead, the A3 resolves to A3 in Book1.
You'd need to use INDIRECT for that to work, but the other workbook would have to be open.
http://www.cpearson.com/excel/indirect.htm
As the workbook has to be open for it to work there's no need to add the file location to the string. It may be useful in some VBA code used in the Workbook open event to automatically open the other workbook though, or look at Excel workspaces to open the other files.
http://www.ozgrid.com/Excel/save-as-workspace.htm
i.e. =INDIRECT("'[Book3.xlsx]Sheet1'!$A$1") or =INDIRECT(Final) if Final is a named value.
Related
I have some VBA functions defined within my Personal.xlsb that I want to use in the Cell formulae for other opened workbooks. I can use these functions within Cell formulae within worksheets in Personal.xlsb, however I can't seem to use these within other opened workbooks... I get the #NAME errors whinging that it can't find the function name.
I hope I've just done something stupid..
FYI for example, one function accepts some arguments including a Cell, and returns an element from the cell's value at a particular position (say Cell.Value = This.Is.An.Example, the function might return "An") effectively replicating a split()[2]
Cheers
You need to reference functions in the Personal.xlsb with the filename, like this:
=PERSONAL.XLSB!myFunctionName(A1)
If you don't want to do that for each function, you can create a reference in your new workbook's VBE. Go Tools > References and find the workbook in the list.
See a walkthrough of the whole process here: https://www.myonlinetraininghub.com/creating-a-reference-to-personal-xlsb-for-user-defined-functions-udfs
I have vlookups to pull specific data from a workbook and paste into a new workbook in the desired layout. The layout of the first workbook never changes however the name will change when i want to run this on a different file.
My current formula is =VLOOKUP(A3,[Workbook1.xlsx]Sheet1!$B$3:$XFD$7,2,FALSE)
I would really like it to reference A1 instead of Workbook1 so I could then just update the file name in A1 every time I want to analyse a different file. I should mention the Sheet name won't ever change.
I know you have to use INDIRECT but im unsure how it works. I did try =VLOOKUP(A3,INDIRECT(A1),$B$3:$XFD$7,2,FALSE) but then i'd too many arguments and when i removed the $B$3:$XFD$7 i lost the range i was searching in.
Thanks!
With INDIRECT you must create the whole string that denotes the range reference:
=VLOOKUP(A3,INDIRECT("'[" & A1 & "]Sheet1'!$B$3:$XFD$7"),2,FALSE)
One more note, that INDIRECT requires that the workbook be open to function, or will return an error.
I'm trying to create a dynamic reference within a formula; meaning the referenced workbook and subsequent sheet name can be changed and the appropriate data loaded.
I'm aware that a static formula reference could be done as follows:
=SUM('C:\Reports\[SOTDJ17.xlsx]Summary'!C10:C25)
but I want to be able to change the workbook name, and it will reference information from that particular workbook and change the data. The workbook name
is stored in B5 and the sheet is stored in B8. I thought I might be able to use
something simple like:
=SUM('C:\Reports\[B5]B8'!C10:C25)
but it doesn't seem to work. Is there a syntax error or something else I am missing?
(I should note that I am trying to reference a closed workbook)
You'll want to use Indirect():
=SUM(INDIRECT("["&B5&"]"&B8&"!$C$10:$C$25"))
Note that the workbook you're referring to must be open.
Before I jump into a VBA solution, I wanted to know if it was possible to update a filename of a closed workbook I am referencing.
The formula reads,
=SUMIF('L:path\[filename - "&TEXT(WORKDAY(TODAY(),-1),"yyyymmdd")&".xlsx]Sheet'!$BF:$BF,"criteria",'L:path\[filename - "&TEXT(WORKDAY(TODAY(),-1),"yyyymmdd")&".xlsx]Sheet'!$DX:$DX)
To clarify, the path the filename would look something like this, This is the filename - yyyymmdd.xlsb
Someone at work said it's not possible to change the filename because it's a string. If that is the case could someone just expand on that a bit?
You can't really. If you have "Book1.xls" and "Book2.xls", what you can do it put this formula in book1:
=MID(CELL("filename",A1),FIND("[",CELL("filename",A1))+1,FIND("]", CELL("filename",A1))-FIND("[",CELL("filename",A1))-1)
This will return the name (only) of Book1. You could then reference that cell from Book2. HOwever, if you change Book1's name to something else, the reference will be broken and you will have to manually change the reference (pick the file from the update link manager). It seems excel uses absolute paths, including filename, to reference other workbook. You would need to have a way to store a flexible reference to that workbook into Book2. But the only way to do is VBA.
Interestingly however you can do that:
Create a reference in book2 pointing to a cell in book1. You get the value of that cell in book2.
Close everything.
Open only book1, edit the referenced cell. Close & save book1.
Book2, when you open it, will ask you if you want to update the link, and you can see the updated value even if book1 is still closed.
The other idea that I had was to use INDIRECT, like what is done there: using indirect function in Excel
But it won't work for closed workbook and that's one of your requirements.
So VBA it is.
I have a Master workbook in MS Excel that references data in 4 other workbooks.
When it opens I get the following message:
We can't update some of the links in your workbook right now.
You can continue without updating their values, or edit the links you think are wrong.
[Continue] [Edit Links...]
Each referenced workbook contains a N row, 365 column rectangular range that I have named 'DataRange'
My master workbook contains 4 lots of N row, 365 column ranges with Array Formula linked to these named ranges:
{='C:\Path\[Workbook1Name.xlsx]Sheet'![DataRange]}
It feels like i've come across an Excel bug.. Anyone know what I'm doing wrong?
Are you using MS Excel 2013, when you receive this error?
If so, it maybe due to the "3D reference in your named DataRange" in Excel 2013 or because you're referencing a range or cell in a closed workbook.
Excel allows the defining of names that refer to specific cells or ranges of cells in that workbook, similarly (using the Define Name tool in the Formulas tab) you can assign a formula to a name and then use that name in place of the formula.
The named formula or named data range is part of a collection in that workbook's (workbook1) objects and can be used in different workbook (workbook2), but the link to the defined name in the other workbook must be done one of two ways.
Link the defined name with a formula like this
='C:\Folder\Path\Workbook1.xls'!NamedFormula or NamedDataRange
Or Create a defined name in workbook2 (it can have the same defined name as workbook1's or a new name) and then refer workbook2's defined name to workbook1's defined name. Select Define Name on the Formula tab and copy a link like this in the Refers To Field:
='C:\Folder\Path\Workbook1.xls'!NamedFormula or NamedDataRange
Note these links will only work when being used in simple formulas which treat the link as a direct links. It will not work with more complex formulas when the original workbook (workbook1) is closed because the link is often treated as an indirect link in complicated formulas.
To work around this issue, use either of the following methods:
Save workbook1 and workbook2 as .xlsb files.
Do not add an external reference link to a defined name that refers to a 3D reference or named range.
Or open both workbooks
For more detail information, please refer to the following link:
https://support.microsoft.com/en-us/kb/2755120
If you're still receiving an error/ warning message after trying all my above suggestion. You might want to some troubleshooting.
Try this:
- Open Excel. Under Tools->Options->Calculation, select the Update remote
references box.
Open your workbook. Make sure the box the remote reference box is checked. Save your workbook this way after updating the link. Close workbook and Excel.Restart Excel and open your workbook.
- Look under defined names and delete all that you don't need or that have broken formulae. Run a FindLink search, to pin point the problem.
This process worked for one of workmates with this exact problem.
I hope this helps, if not let me know. There might be a 4th solution.
I finally solved this issue after going on a scavenger hunt. In my case, the reference was to an old file that no longer exists, and removing the reference was all that was needed. Unfortunately Excel does not pinpoint where the reference is, so it was a pain to look for the cell that was making the reference.
In my workbook, it was a reference as a part of a Data Validation. For others seeing the same error, I recommend using the Find & Select -> Go To Special feature (Home ribbon tab) then searching by Formula errors and and Data validation.
Open Excel
Go to "Inquire" tab page in the ribbon
Select "Workbook Analysis"
Check Items\Cells\With Validation Criteria items. In the "Validation Text" you might spot references to the extenal source.
The "Cell Address" column would give you the list of problematic cells.
Look around any other supsicious findings of the Workbook Analysis tool
Have you considered giving the data ranges different names? DataRange1, DataRange2 etc, or is this not possible due to other constraints. When excel says "some" of the links, how far has it got?
I got it working by ditching the FormulaArray and set the FormulaR1C1 for the entire range. Unfortunately the formula was a bit more complicated.
=INDEX(
'C:\Path\Workbook1Name.xlsx'!DataRange,
ROW() - ROW(Workbook1DataRange) + ROW('C:\Path\Workbook1Name.xlsx'!DataRange) - 5,
COLUMN() - COLUMN('C:\Path\Workbook1Name.xlsx'!DataRange) + 1)