Concatenate seem to wrap in quotes prior to indirect - excel-formula

Goal: Pull data from another excel sheet but name of excel sheet is changed yearly
Thoughts: Excel seems to wrap the below in double quotes. While this may be the problem it is unclear how to resolve it.
=INDIRECT(CONCATENATE(B2,"FY",RIGHT(Financal_Year,2),"_Attendance","\","[FY",RIGHT(Financal_Year,2)," LOG.xlsx]JUN'!B19)"))
In "Show Calculation Steps" I can see that the evaluation looks correct with the EXPECTATION of the double quotes placed where concatenate place its data.
Example Output:
=INDIRECT("'\\networkdrive\FY18_Attendance\[FY18_LOG.xlsx]JUN'!B19")
The output I'm looking for:
=INDIRECT('\\netwrokdrive\FY18_Attendance\[FY18 LOG.xlsx]JUN'!B19)
This way it grabs the data in that block.

If it were me, I would create a shortcut to the current year file and then link my references through that shortcut. Then every year you only have to update what the "current fy" link points to and all other refs fall in line.
I.e. if you want fy18's cell b19 you would insert the following into a cell.
='\\server\path\[current-fy-shortcut.lnk]sheet1'!b19
And then change the current-fy-shortcut to point to fy18-blahblah.xlsx
There may be a way to build the fy reference with indirect but it seems like a whole lot of work for worse payoff. You have to open the referenced workbook for indirect to "see" it(every time). with the method above you just have to change a pointer once a year.
Hope this helps,
SySfS

Related

Using a variable for a data reference in COUNTIFS

I am summarizing data from a table in another workbook using sth like
COUNTIFS(filename.xlsm!Sheet[DataReference];">=1/1/2021";filename.xlsm!Sheet[DataReference];"<=31/3/2021")
I have create these formulas for 16 quarters and am using the same formula for many data references. To avoid errors (and trying to save manually editing the data reference in every cell twice), I would like to have a field in my row that holds the value for "DataReference" and use that as a variable inside the reference. This way I can copy&paste the formula in many rows and only need to plug in the right data reference and avoid further errors/inconsistencies.
But neither by googling nor by trial and error have I found a way for Excel to accept a variable inside the brackets
I found it! I need to use INDIRECT and build the path:
COUNTIF(INDIRECT(<cellwithfilename>&"!"&<Cell with worksheet name>&"["&<cell with data range>&"]"; ....

How to insert a formula by macro?

The issue has been solved.
It would appear that when I made some changes to capture data a little while ago, I inadvertently broke the order of things. When the above bit of code was running, the [Date Out:] column was indeed empty, so Excel was reporting properly.
I've since reordered the input of formulas and now the sheet works correctly, with credit to #BigBen and #Michael Wycisk.
I created an Excel sheet to draw together the data from several other Excel sheets into one to keep track of a project.
I have a formula that works if it is written into a range of cells with the source data sheet open in the background. If I ask a macro to put it into the required cells as the main sheet opens then the formula fails. By 'fail', I mean the formula checks it's first column to see if data is present or not and then decides that the column is empty regardless, therefore falsely reporting 'nothing sent' if there is a date in the "Date Out" column.
Here is the line in question.
WSR.Range("ReportTable[Latest Portare Instance:]") = "=IFERROR(IF([Date out:]="""",""Nothing Sent"",IF(AND([Received by Serial:]="""",[Received by Asset:]=""""),""Not Received"",IF([Received by Asset:]<>"""",LOOKUP(2,1/('Stock Movement Archive Defra.xlsx'!Archive[Asset No:]=$J2),'Stock Movement Archive Defra.xlsx'!Archive[Location:]),LOOKUP(2,1/('Stock Movement Archive Defra.xlsx'!Archive[S/No:]=$I2),'Stock Movement Archive Defra.xlsx'!Archive[Location:])))),""Issue"")"
It's one of several formulas, all inserted the same way and the rest work. As far as I can tell the formula is being inserted correctly, just that this one stops at the first if statement.
For reference, I have tried changing the first 'if' statement to start IF([Date out:]<>"""", the formula then either states "Nothing Received" where there is no date or pulls the correct data if there is a date. Also tried changing the format of the "Date Out" column.
The formula looks fine for me. The only problem might be that you need to use the .Formula property after the Range object:
WSR.Range("ReportTable[Latest Portare Instance:]").Formula = "=IFERROR(IF([Date out:]="""",""Nothing Sent"",IF(AND([Received by Serial:]="""",[Received by Asset:]=""""),""Not Received"",IF([Received by Asset:]<>"""",LOOKUP(2,1/('Stock Movement Archive Defra.xlsx'!Archive[Asset No:]=$J2),'Stock Movement Archive Defra.xlsx'!Archive[Location:]),LOOKUP(2,1/('Stock Movement Archive Defra.xlsx'!Archive[S/No:]=$I2),'Stock Movement Archive Defra.xlsx'!Archive[Location:])))),""Issue"")"
To make sure that your formula is correct (you say it works fine when typed into the cell), you might type it into the cell, select the cell and then type ?ActiveCell.Formula into the Immediate Window inside the VBE (don't forget to check that the quotation marks are correct).

Hyperlink formula not working despite displaying correct address

I am using the formula:
=HYPERLINK(CELL("address",INDIRECT("'"&C38&"'!A1")))
Where C38 contains
0999-0165
and I have a sheet called 0999-0165. There are no leading or trailing characters, and since the name in C38 is generated by the sheetname there is no error between 0 and O.
The sheet has also been saved to my desktop as dtest.xlsx
When I click on the formula, I get the following error:
MS Help indicates that I should be going down the right path here:
Where did I go wrong
What do I need to do to adjust this formula to make it work so that I can simply copy the formula up or down to create other links for other reference sheetnames in column C?
I also did the work around from this question but it did not seem to help.
Muddying the water
When I use a direct cell reference and drop the indirect part for testing purposes to make it look the same as the MS Help recommendation, I wind up with the same error:
=HYPERLINK(CELL("address",'0999-0165'!A1))
And BTW, the above formula winds up displaying the same as the Indirect one. Complete with adding the $
Here's a long workaround to this, if you don't want to hard-code the workbook name. Get the entire filename with CELL("filename",A1) and then extract just the workbook name and the enclosing brackets using MID and FIND.
=HYPERLINK(MID(CELL("filename",A1),FIND("[",CELL("filename",A1)),FIND("]", CELL("filename",A1))-FIND("[",CELL("filename",A1))+1)&"'"&C38&"'!$A$1")
Or slightly more simple:
=HYPERLINK(SUBSTITUTE(SUBSTITUTE(CELL("address",INDIRECT("'"&C38&"'!A1")),"'[","["),"]","]'"))

Change the file reference in a formula using the content of another cell

I need help with a formula (or macro) please.
On the printscreen below ColA and Row1 are copied in via a macro and cells c2 down and right are formulas.
The problem I have is when Row1 is copied in next time the project names might change (say a new one called "100 Project") and I will need to change the filename in the formulas in C5 onwards.
I don't want to use INDIRECT as I can't have 70 or so files open.
Is there a formula I can use please or does anyone have a macro that'll do the job?
Printscreen
Show us a full circle of what you want to use, what you want to do with it and what the end result should look like. (you can reference the screenshot provided) as I'm not quite clear of want you want to do and don't want to guess.
In any case:
=CELL("filename",A1) should help you with current file name however you rename the document you work on.
Other than that you can import however many filenames you have on a list without needing to open them. We will expand on that should it be needed.
PS Based on updated info:
=INDIRECT(CONCATENATE("'",$C$3,"'","!","A",ROW()))
The reference to make that formula work is C3
This is integrated instead of your
" 'g:\it\capex\2015 etc etc tec ... Plan'!$B$20:$B$119 "
C3="C:\folder\[filename.xlsx]sheet name"
(derived by formula or however you want - the result shows the address)
If you want to put in the sheet name independently or more flexibly simply add one more ,references for it to the concatenation.
Either adjust the formula to accommodate your C3 or adjust your c3 to accommodate the formula its fairly simple = you can do it more easily when you remove the INDIRECT and see what remains as text. Get the correct text running through that and you can need correct reference. You can use the general idea to create dynamic address lists that you can reference from 1 location. Further more vba can pull names from directories so you can compile an active list, leaving you with little to no manual work... Yes - most people usually frown upon crafting location addresses in formulas and usually tell you to reorganize your work files, but some times its necessary to access files ad-hoc on value based references.

Run a text formula in an adjacent cell

I'm having trouble trying to figure out a way to have two columns, one to show the entire formula that can be editable and the second to actually perform the formula.
Ideally, I would like my sheet to be set up like this:
Formula | Value
=5+2 | 7
=3-2 | 1
I would like to be able to change the Formula column and have it automatically update the Value column.
I've tried using the GetFormula() function but I don't think that's what I want to do as I would end up in a circular reference based on what I want to do. The closest I've got is using a Right() function and Text in the formula column or a space and removing the space. However, I end up with the text and not the solved formula instead.
Using =RIGHT(A2, LEN(A2)-1)
Formula | Value
=5+2 | =5+2
I have also tried using =RIGHT(A2,LEN(A2)-1) but without the "=" and can't figure out how to convert the "5+2" into text that I can use to solve. I'm hoping to do this with a formula and without a macro/VBA.
Here is how to do it.
1
Open the Name Manager. Control-F3 from the worksheet, and then click the New button.
2
For the Name field in the dialog, enter EVALA. I just picked this name; it stands for "Evaluate A". But you can pick whatever name you like.
3
For the Refers to field, enter this
=EVALUATE($A1)
4
Click OK and then Close.
5
In B1 enter this formula:
=EVALA
That's it.
You can now use this formula on any row in the worksheet and it will evaluate whatever is in the column A cell of the row where you enter the formula.
You can make a user defined function easily enough with VBA, but if you don't regularly use VBA then an alternative method is to create a Name object. Name objects can access certain functions not typically available in a cell's formula. One of these functions is "Evaluate" which will evaluate a string as a mathematical expression. Here's a demonstration how to do this.
NOTE: Pay special attention to the use of $. Chances are you don't want any $ in your name definition since that will prevent it from behaving in a relative manner. Also, Sheet1! means that this will not work on another sheet.
Update I just want to give credit for this method to the following sources. This is pretty neat stuff, so for anyone interested give it a read. The last link in particular gives a neat example of creating a chart with no data points.
MSDN Evaluating Defined Names
The power of evaluate (ozgrid)
XL4 Macro Functions in Names - JKP
Evaluate and Indirect
More unique functionality of Defined Names
This is probably the best solution for the OP, since it asks to avoid using VBA; however, this method is somewhat limited. It requires manual set-up on every sheet to be used. Much preferable I think is to create a very simple UDF like this...
Function Eval(Expr As String)
Eval = Application.Evaluate(Expr)
End Function
This can be added to any accessible add-in, making it available to any instance of Excel. A little more set-up, but less maintenance.
Just put a single ' before the formula in your A column:
'=5+2 will show in your cell as "=5+2". Then in the B column, just do the formula as normal, =5+2.

Resources