Formula works in excel, but name does not - excel

I have this formula in excel, to return a row number:
=MATCH(INDIRECT(ADDRESS(ROW(),4)),DayOffRequests!$A$1:$A$100,0)
and it works just fine.
I would like to make a new name (DAYS_OFF_ROW) and assign it to this formula.
Here's what I did in the name manager:
But when I write this into a cell: =DAYS_OFF_ROW it says #VALUE! whereas when I write the same formula into the cell, it gives me the row number I am looking for.
Why is does it say #VALUE! and not the row number like the formula does?

First off Row() returns the row on which the cell resides. If you put Row() in indirect you will get an error since there is no cell for which Excel can find a Row(). So right off the bat, your formula is nonsense for a named range.
Second, even if there was some magic way for Excel to know which Row() you cared about here, Match doesn't return a range. Just a position in an array like "5" or "50". When you use a formula to define a named range, the result of the formula MUST be a range. So you could do another Indirect like =Indirect("A" & Match(foo,bar)) or something so that the result out of your formula actually refers to a range in your sheet.

It works if i set the name to this formula: =MATCH(!$D1,DayOffRequests!$A$1:$A$100,0)
Of course i have to be in field A1 when setting the name. Now its reference the fourth column and whichever row i am in.

Related

Get Excel cell relative reference into a cell

I am trying to find how to get an excel formula to get a cell's relative reference into a cell.
A formula that would be like =getcellreference(B2) and then has B2 as the output.
Nothing complicated but i could not find a simple solution.
You can use CELL():
=CELL("address",B2)
For formatting to literally show B2 instead of the absolute reference, you can do:
=SUBSTITUTE(CELL("address",B2),"$","")
If all you are trying to do is output a cell reference that you manually input, then all you need to do is:
="B2"
or
B2 (no equals sign)
You can use the ADDRESS function to obtain the address of a cell in a worksheet, given specified row and column numbers
ADDRESS(row_num, column_num, [abs_num], [a1], [sheet_text])
So for cell B2, you will need to put =ADDRESS(2,2) where the first 2 stands for the row number and 2nd is for column B.

Unable to use SUBSTITUTE(ADDRESS(MATCH))) combination as a range in a LOOKUP function in Excel

I have an Excel sheet containing a matrix of [Year & Week number] in rows and [name of Employees] in row1 giving values of available weekly hours.
I am able to successfully use the Excel formula
=LOOKUP(2,1/((A:A=2018)*(B:B=31)),D:D)
at cell F2 for a reverse lookup. It gives the result 15 correctly.
However, I wanted to replace range D:D in the above formula to a dynamic range by identifying the column when the employee is known.
So I tried replacing by the formula
SUBSTITUTE(ADDRESS(1,MATCH("Employee2",1:1,0),4),"1","") &":"&SUBSTITUTE(ADDRESS(1,MATCH("Employee2",1:1,0),4),"1","")
This portion of the formula works and gives D:D for Employee2. This is shown to work in cell F4.
But the revised formula gives an error of #Value! at cell F6.
It says "A value used in the formula is of the wrong data type."
The revised formula which does not work is:
=LOOKUP(2,1/((A:A=2018)*(B:B=31)),SUBSTITUTE(ADDRESS(1,MATCH("Employee2",1:1,0),4),"1","") &":"&SUBSTITUTE(ADDRESS(1,MATCH("Employee2",1:1,0),4),"1",""))
I hope someone can help show me where I am making an error in trying to replace range D:D in the LOOKUP formula with the combination of SUBSTITUTE, ADDRESS & MATCH functions.
Thanks to all trying to help in advance.
You cannot just plug a string, which is what SUBSTITUTE returns into a formula.
You can use INDERICT to turn the string into a viable reference:
INDIRECT(SUBSTITUTE(ADDRESS(1,MATCH("Employee2",1:1,0),4),"1","") &":"&SUBSTITUTE(ADDRESS(1,MATCH("Employee2",1:1,0),4),"1",""))
But both INDIRECT and ADDRESS are volatile.
Use instead INDEX to return the correct column:
INDEX(A:AAA,0,MATCH("Employee2",1:1,0))
So your formula is:
=LOOKUP(2,1/((A:A=2018)*(B:B=31)),INDEX(A:AAA,0,MATCH("Employee2",1:1,0)))

Excel formula that combines MATCH, INDEX and OFFSET

I am having trouble with an Excel-function.
On sheet A I want to get the value of a cell that is located x-columns to the right of cell F2.
X is a variable number and is determined by the value of cell A1. Currently, the value is 5.
=(OFFSET(sheetA!F2,0,sheetA!A1))
This formula works. However, I want to include this function into a MATCH and INDEX function that is located on another sheet (B).
I know that I can use the following formula to get value of $F$2
INDEX(sheetA!F:F,MATCH(sheetB!C4,sheetA!A:A,0))
Combining them, results in the following formula:
=INDEX((OFFSET(sheetA!F2,0,sheetA!A1)),MATCH(sheetB!C4,sheetA!A:A,0))
This formula generates a #REF!-value.
If I evaluate the formula, I see the following steps:
=INDEX((OFFSET(sheetA!$F$2,0,5)),MATCH(sheetB!C4,sheetA!A:A,0))
=INDEX((sheetA!$K$2),MATCH(sheetB!C4,sheetA!A:A,0))
=INDEX((sheetA!$K$2),MATCH("BTC",sheetA!A:A,0))
=#REF!
Why do I want to use MATCH and INDEX?
Because while the values on sheet A are "fixed", the values of sheetB!C4 are floating/variable. Therefore, I need to locate the correct row first. The correct column can be done with the offset-part.
Thank you for your help.
Try this
=INDEX((OFFSET(SheetA!F:F,0,SheetA!A1)),MATCH(SheetB!C4,SheetA!A:A,0))
Syntax of INDEX is
INDEX(array, row_num, [column_num])
where, array is range of cells. When you use =INDEX((OFFSET(sheetA!F2,0,sheetA!A1)),MATCH(sheetB!C4,sheetA!A:A,0)), (OFFSET(sheetA!F2,0,sheetA!A1)) returns sheetA!$K$2 which is a cell not a range.

Excel formula reference cell above last cell in range

I'm trying to set up a formula to automatically calculate the % change between the most recently added cell in a range (which includes #N/A values at the bottom of the range) and the cell immediately above it. I've been using this formula to obtain the value of the bottom not #N/A cell:
LOOKUP(2, 1/NOT(ISNA(G8:G19)), G8:G19)
Which is working fine. My first thought on how to reach the cell above it was to use OFFSET, like so:
OFFSET(LOOKUP(2, 1/NOT(ISNA(G8:G19)), G8:G19), -1, 0)
but this gives me an error, I think because the lookup function is returning the value in the cell rather than the cell reference. How should I format a function to return the value of the cell above the last non-N/A cell in a range?
Try this alternative for seeking the last non-error, numerical value in column G.
=index(G:G, match(1e99, G:G))/index(G:G, match(1e99, G:G)-1)
Using MATCH to find the last number in a column returns the row number to INDEX. It is a simple matter to subtract 1 from a row number.
One method is to use this array formula:
=INDEX($G$8:$G$19,MATCH(2,IF(NOT(ISNA($G$8:$G$19)),1))-1)
Being an array formula it must be confirmed with Ctrl-Shift-Enter on exiting edit mode instead of enter. If done properly then Excel will put {} around the formula.

INDIRECT inside INDEX function giving #REF error

I'm have an excel workbook Spreadsheet.xlsx in which B2=MATCH(B1,'\\SERVER\Path\To\File\[Workbook.xlsx]Sheet1'!$A$1:$A$500,0) takes the string (a name) in in B1 and matches it to a column of row headers in Workbook.xlsx, to give the row number.
Currently B2 returns a value of 8, which is used in B3=INDEX('\\SERVER\Path\To\File\[Workbook.xlsx]Sheet1'!$A$8:$SD$8), MATCH($A4,'\\SERVER\Path\To\File\[Workbook.xlsx]Sheet1'!$A$2:$SD$2,0)).
B3 indexes a range of values $A$8:$SD$8 corresponding to the row number from B2 in Sheet1 in Workbook.xlsx, and returns the values matched to a date $A4 in the range $A$2:$SD$2.
Currently I am manually typing in the row number to B3 range `$A$8:$SD$8.
If I try to automate this using B3=INDEX(INDIRECT("'\\SERVER\Path\To\File\[Workbook.xlsx]Sheet'!$A$"&B2&":$SD$"&B2), MATCH($A4,'\\SERVER\Path\To\File\[Workbook.xlsx]Sheet1'!$A$2:$SD$2,0)), I get a #REF error.
I have used INDIRECT elsewhere e.g. =MAX(INDIRECT(K&"K1")) and it has worked just fine.
Also, Workbook.xlsx and Sheet1 in it definitely exist, and I am able to get data from them without using INDIRECT.
Why doesn't it work?
INDEX and MATCH functions, as used here, do work with closed workbooks - INDIRECT doesn't
...but you don't really need INDIRECT here - you can use this version with B2 defining the row number in the first range
=INDEX('\\SERVER\Path\To\File\[Workbook.xlsx]Sheet1'!$A$1:$SD$500),B2, MATCH($A4,'\\SERVER\Path\To\File\[Workbook.xlsx]Sheet1'!$A$2:$SD$2,0))
That should work even if the source workbook is closed, and is a "cleaner", more robust approach in any case.
Note that the first range in the formula is changed to be as long as your match range from B2
If you want you can cut out B2 altogether, just put the MATCH function from B2 in that formula in place of B2, i.e.
=INDEX('\\SERVER\Path\To\File\[Workbook.xlsx]Sheet1'!$A$1:$SD$500),MATCH(B1,'\\SERVER\Path\To\File\[Workbook.xlsx]Sheet1'!$A$1:$A$500,0), MATCH($A4,'\\SERVER\Path\To\File\[Workbook.xlsx]Sheet1'!$A$2:$SD$2,0))
[Note: as Jerry mentioned, your sheet names weren't consistent so I changed the first to Sheet1 to match the others]

Resources