Using INDEX MATCH across multiple sheets with a named range - excel-formula

On Sheet A, I have the named range salaries2010. My goal is to reference a value from that range on Sheet B.
On Sheet A, this formula returns the correct value:
=INDEX(salaries2010,6,MATCH(C518,INDEX(salaries2010,1,0),0))
I know Sheet B able to reference the named range salaries2010 because this formula, in which I just point to the cell without using MATCH, returns the correct value:
=INDEX(salaries2010,6,1)
Alas, on Sheet B, my original formula doesn't work, even after I change the search term to C51 (where the same term resides)
=INDEX(salaries2010,6,MATCH(C51,INDEX(salaries2010,1,0),0))
I get the #NA! error.
Any ideas on what's wrong? Some idiosyncrasy of looking things up between sheets?

You can also Evaluate the formula(Formulas => evaluate formula on ribbon), and check where the N/A result returns.

Related

How can I reference a cell on a different sheet using a formula to determine the source location?

I am using Excel 2016. On Sheet A, I am trying to define a range of Sheet B cells based on the contents of those cells. Sheet B has roughly 60k rows in about 250 groups based on the contents of Column A. For a given value in Column C on Sheet A, I am using successfully using something like MATCH(C7,'Sheet B'!$A:$A,0) to find the first row of a group and MATCH(C7,'Sheet B'!$A:$A,1) to find the last row. So far, so good.
Ultimately, I'm trying to use the row values determined by values in Column A above to help define a range in Column B that I can use for further evaluation. However, I think I just don't know the right way to define the column value. I've been using COUNTA as a check, and it's failing every time.
=COUNTA('Sheet B'!"B"&MATCH(C7,'Sheet B'!$A:$A,0):'Sheet B'!"B"&MATCH(C7,'Sheet B'!$A:$A,1)
Use INDEX:
=COUNTA(INDEX('Sheet B'!B:B,MATCH(C7,'Sheet B'!$A:$A,0)):INDEX('Sheet B'!B:B,MATCH(C7,'Sheet B'!$A:$A,1)))

Using SUMIF within VBA

enter image description hereI need a little help with VBA to perform the Sumif function.
I have a file and need to extract from sheet2: Using the normal formulas, the function is thus:enter image description here SUMIF (Sheet2! B: B; Sheet1! A: A; Sheet2! C: C)
However, I want them in VBA, can give this small force :)
I've tried a few things, but it always returns zero. Then follow the criteria to get help with new ideas
Your worksheet formula is using 'implicit reference' for the Sheet1!A:A criteria. Normally, you would use,
=SUMIF(Sheet2!B:B; Sheet1!A2; Sheet2!C:C)
... in Sheet1!C2 (or any other cell) and fill down for Sheet1!A3, Sheet1!A4, etc. as the criteria. There is no 'implicit reference' because you are explicitly referencing one specific cell in Sheet1's column A. By using,
=SUMIF(Sheet2!B:B; Sheet1!A:A; Sheet2!C:C)
... as a standard formula you are implicitly referencing the cell in column A which is in the same worksheet row as the formula. When the formula is in row 5, Sheet1!A5 is referenced as the criteria; when it is in row 99, Sheet1!A99 becomes the criteria.
The concept of 'implicit reference' (aka 'inferred reference') can be easily demonstrated with this simple exercise.
Put 5, 10, 15, ... 40, 45, 50 into cells A1:A10.
In any unused column to the right, pick a row between 1 and 10 and put in the formula,
=a:a
The result will be the value from column A in whatever row you put the formula into.
Without a cell (in VBA known as Application.Caller) to provide the implicit or inferred row, the formula becomes confused as to what cell in column A to implicitly reference. Using the simplified example provided above, VBA has no row reference to determine how to resolve A:A to a single cell reference. My best guess in that it is trying to reference either Sheet1!A1 or Sheet1!A1048576 as the criteria.
Hope I've explained that concept sufficiently. Comments welcomed and I'll try to respond.

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.

using =if and Cell in the same formula?

I hope someone can help me.
I am trying to use specific critirea to bring back cell information.
I have some raw data on Sheet 1, and on sheet 2 I have a list of references, I want to know if those references are in my raw data on sheet 1 and if so, tell me what cell it is in.
the formula I have tried is:
=IF(Sheet1!A:A=Sheet2!A1,Cell("row"),0)
This just brings back '0' all the time, even though I know the data is in sheet 1.
Can anyone help me please?
Unfortunately you cannot compare a range to a single cell Sheet1!A:A = Sheet2!A1 in Excel without array formulas.
Instead, use the MATCH function, which returns the position of a matching cell. In your case:
`=MATCH(Sheet2!A1,Sheet1!A:A,0)`
If your search range extends in a single column (e.g.:[A1:A100]), then you could try the following, which will inform you: a) if your lookup value was not found, and b) if the value is found, it returns you in which row it was found for the first time only. That is, if the lookup value exists in more than one cells inside your search range, this function will return only the row of the first cell containing the value.
In this example, B1 is the lookup value, and A1:A10 the search range:
=IF(ISNA(MATCH(B1;A1:A10;0));"does not exist";CONCATENATE("found on row:";MATCH(B1;A1:A10;0)))

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