Sum of index matches for dynamic range of columns - excel

On Sheet2 I am trying to sum the values in a row of a range on Sheet1 over a dynamic range of columns based on a lookup value for the from column and a fixed variable for how many columns to right of that lookup value for the to column.
I am using INDEX-MATCH to find the from cell based on certain reference, INDEX-MATCH with a reference added to the column lookup to find the to column, and CELL to get the position rather than value of the results.
What I have is the following:
=SUM(
CELL("address",
INDEX(Sheet1!$B$4:$BA$36,MATCH($A$1,Sheet1!$A$4:$A$36),MATCH(D$3,Sheet1!$B$3:$BA$3,0)))
&":"&
CELL("address",
INDEX(Sheet1!$B$4:$BA$36,MATCH($A$1,Sheet1!$A$4:$A$36),MATCH(D$3,Sheet1!$B$3:$BA$3,0)+'Control Panel'!$C$2)))
Control Panel!$C$2 is my variable for how many columns to the right of the from column I want the to column to be.
Obviously, this is not working. I suspect it's because the concatenated text in the SUM() reference the full file name rather than 'Sheet1'![from]:[to]. Not sure if this is the case, but also can't figure out how to get just the A1 cell position for the to.
Any ideas how I can get this to work?

Figured it out:
=SUM(INDEX(Sheet1!$B$4:$BA$36,MATCH($A$1,Sheet1!$A$4:$A$36),MATCH(D$3,Sheet1!$B$3:$BA$3,0))):INDEX(Sheet1!$B$4:$BA$36,MATCH($A$1,Sheet1!$A$4:$A$36),MATCH(D$3,Sheet1!$B$3:$BA$3,0)+'Control Panel'!$C$2))
Literally just needed a colon between the two index-matches. Still not sure why this works, as the index-match should return a value.

Related

Return multiple matches when range is dynamic

I have a column which is a dynamic named range:
A
A
B
C
A
How can I apply a MATCH or other formula which returns the row or cell address of all A values in the dynamic named range?
A dynamic named range is used so all row or address of A values can automatically appear as a spill rather than having to drag down the formula.
I have seen numerous formulas in this structure:
=INDEX($B$2:$B$8, SMALL(IF($A$11=$A$2:$A$8, ROW($A$2:$A$8)-ROW($A$2)+1), ROW(1:1)))
However, most of these seem to return the first instance (row or cell address of the first match) and requires the formula to be dragged down manually rather than a spill, which is more preferable.
Any help will be greatly appreciated.
Use FILTER:
=FILTER(ROW(A1:A5),A1:A5=C1)
This will return the Row number everywhere they match.
From there it is pretty easy to include that in INDEX:
=INDEX(B:B,FILTER(ROW(A1:A5),A1:A5=C1))
If you do the full column in the index, you do not need the ROW($A$2:$A$8)-ROW($A$2)+1 as returning the actual row instead of relative works just fine.
Try something like =SORT(ROW($A$1:$A$5)/($A$1:$A$5=$C$1)). This will get you the matches of a value in C1 with a spill formula, leaving behind #DIV/0 errors
See example below:
Other answers that you might be able to take ideas from are here: Match Exact Row Number of Nth Largest Value In Data With Duplicates
You could be thinking of:
=SMALL(IFERROR(ROW(A1:A5)*MATCH(A1:A5,C1,0),FALSE),ROW(A1:INDEX(A:A,COUNTIF(A1:A5,C1),)))
Where your data start in A1 and your compare value is in C1.
If you have Excel 365, this is easier:
=INDEX(SORT(ROW(A1:A5)*MATCH(A1:A5,C1,0)),SEQUENCE(COUNTIF(A1:A5,C1)))
or better yet:
=LET( dataRange, A1:A5,
compareTo, C1,
INDEX(SORT(ROW(dataRange)*MATCH(dataRange,compareTo,0)),SEQUENCE(COUNTIF(dataRange,compareTo))) )

VBA: vlookup through multiple columns

this is my first question so I will try my best to format this.
I would like to use the vlookup function in more than just one column. It seems impossible to do is in the formula for the large data set, so maybe someone with VBA knowledge can help me.
In my excel file I've two spreadsheets:
Sheet1 with one column "A" with 16868 different processes ID's.
Sheet2 with columns from "A" to "HX", where "A:HW" are different processes ID's (each column have different numbers of rows) and in "HX" column I have a region for the particular row of processes.
What I am trying to achieve is to do vloop for sheet1 column "A" that will look for each record in table sheet2 and return "HX" when found it.
In example:
I'm looking for "A2" cell in sheet1 in table_array sheet2 "A:HX". If found it then return cell in the same row but from column "HX". The trick here is when the looking value is not in the sheet2 column "A", then it should vlookup in column "B", then "C" and so on till "HW". There is an option where the looking value might not be in sheet2 at all and then the formula should return "0".
Is it possible to do this in VBA or excel formula?
Firstly, please NEVER use VLOOKUP. Ever.
An INDEX/MATCH combination is always better in every way. It is faster, more flexible and more robust as it does not break if you insert columns. It is also (arguably) easier to use as you do not need to count columns.
Anyway, back to the problem at hand. You can use an INDEX/SUMPRODUCT combination for this:
=INDEX(<range of return values>),SUMPRODUCT(--MAX((<range to search in>=<value to search for>)*ROW(<range to search in>)))-(ROW(<range to search in>)-1))
The SUMPRODUCT returns the last row number where the value is found.
The last bit -(ROW(<range to search in>)-1) is just to make the returned value relative to the searched range (rather than an absolute row number.
The INDEX is then uses this value to select a value from the HX column.

Validation by Using CONCAT in COUNTIF

I want to concatenate the value of two columns in the current sheet and then result should be compared with the concatenation of two column value in another sheet.
e.g - The entered value in Column W and X in current sheet after concatenation should be compared with the existing value in column Y and column Z(after concat) of another sheet.
I have tried using the formula COUNTIF(Sheet2!CONCAT($W$2,$X$2:$Y$2,$Z$2),A2)>0 and some different alteration in this but it seems COUNTIF has range and criteria as argument and this is string which is causing error.
If you want to compare, a simple '=' will do.
Concatenation can be done using '&'.
in current sheet:
=W1&X1=Sheet2!Y1&Sheet2!Z1
will return TRUE if both concatenations are equal and FALSE if they are not.
To find the value W1&X1 in the entire range, I suggest you use a help column (unless you are willing to write a macro). In the help column of sheet1, you concatenate the values (=W1&X1 - drag down). In the hlep column of sheet2 you do the same. Then you make an additional column to check for matches, by using
=match(ValueHelpColSheet1,HelpColSheet2,0)
This formula returns the row number in which the match is found and an error when the corresponding value is not found. You can replace this error with something else using IFERROR if you want to.

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 How can I direct columns by their headline?

Currently I have a huge formula in my excel sheet:
=SUM(SUMIF(INDIRECT(A9&"!$F:$F"),"working";INDIRECT(A9&"!$B:$B"))+SUMIF(INDIRECT(A9&"!$F:$F");"Open";INDIRECT(A9&"!$B:$B"))+SUMIF(INDIRECT(A9&"!$F:$F");"internal",INDIRECT(A9&"!$B:$B"))+(SUMIF(INDIRECT(A9&"!$F:$F"),"finished";INDIRECT(A9&"!$AP:$AP"))))
In A9 is the name of the excel sheet that the formula has to use. So for example in A3 there's '20140612', so it has to use the excel sheet with the name '20140612'. Furthermore it sums up some values depending on some conditions.
My question is: I would like to direct the columns in the other sheets by their headlines, not their positions in the sheet. So for example le column AP doesn't always has to be in the position AP, but has always the headline 'Points'.
Can you think of an adaption of the formula that can direct the column by their headline?
I though of the MATCH formula. But I'm not to sure where I have to put this in.
I think the simplest answer would be to use named ranges within your sheet. In this way you could name a range (currently in column AP) as 'Points', change your formula to use 'Points' instead of '$AP:$AP' & if you move your points data about the formulas would be unchanged.
If you are planning to keep changing your header row values then you could use HLOOKUP to match up the header column probably in conjunction with MATCH & INDEX.
To answer your question about the usage of MATCH(), it's worth thinking of it as half of a VLOOKUP() or HLOOKUP(), i.e. it's the bit that finds the row or column containing the value you're searching for, then you can use INDEX() to get that row / column from a range you specify.
So, if you know that one of your column headings is "Points", then you could find it by using:
=MATCH("Points", A1:Z1, FALSE)
...which would return 10 if "Points" were the heading of column J for example. If you wanted to then use that column for a lookup, you can use OFFSET() to define that column as a range to use for a lookup, so let's say I wanted to find the text "foo" in the "Points" column, I could use:
=MATCH("foo", OFFSET(A1:Z1000, 0, MATCH("Points", A1:Z1, FALSE) - 1, 1000, 1), false)
... which uses the column index I found before as an input to OFFSET() in order to dynamically reference J1:J1000 and then search for "foo" in that column.
For your example in the question, rather than A1:Z1000 you could use a call to INDIRECT() that would return the entire range of interest from your source sheet.

Resources