I cannot understand why everytime I use INDEX in excel to find a value given the two criteria, I get a #REF error.
INDEX(C2:L1048576,MATCH(O1,A2:A1048576,0),MATCH(O2,B2:B1048576,0))
There were no deleted cells, nor were they shifted at any point in time. They have the same number of rows too. The arrays to search into are correct.
Thanks. I would appreciate if anyone can give me some guidance. I am new to the INDEX formula.
The formula you're using doesn't find a value according to two criteria. The comments you were given explain what you're actually doing.
INDEX returns one cell value from a given range, according to a row and column index - the location within your range, starting with 1. (If your reference has only one row or column, one of them can be omitted).
MATCH finds a value in a range and returns its index.
So finding one value in a one-dimension range is easy using these two functions, using something like this (with a range of one column and multiple rows) =INDEX(range,MATCH(value,range,0),1).
To find two criteria you need to tweak this concept. One way is to use concatenation of strings, using the & operator, and for this you'll also need to use an array formula (entering it using Ctrl+Shift+Enter) like this formula:
=INDEX($C$2:$C$1048576,MATCH(O1&O2,$A$2:$A$1048576&$B$2:$B$1048576,0),1)
It's not clear what you are trying to return, so this formula will return the corresponding value in column C. You can use this concept to return each value from the rest of the columns D:L, one by one, or concatenate them.
Related
I'm struggling to find a work around to this.
Below I have some data. I'm trying to add a formula in Q cells that looks up the value in R, then uses that value to count how many cells are the left of it in the table to the left. Seems a weird thing to do, but I want to use the final result in another formula that fetches a predetermined title.
So in R2 I have 00:37:22. I need the formula to count from the left in the table how many cells (regardless if they are empty or have data) are there until M2 when it finds the matching value. The results should be 13.
I've made a example below of what I've got and what I'm after.
I'm unsure if excel can even do this, and any help would be greatly appreciated.
Thanks
You can use the Match() formula to get the column number of cell that contains matched value.
=MATCH(R9,A9:O9,0)
the formula is (matching value, range, 0 for exact match)
Use the Match function to return the amount of columns
=MATCH(R5;A5:N5;0)
I am trying to use an on sheet formula that will provide me with all the column numbers in which a value exists. For the sake of example: I want to find all the columns on Sheet1 that have a value of ThisHeader in Row1.
I have been able to use the below formula to retrieve the result I want if the value I'm searching for only appears one time:
=MATCH("ThisHeader",1:1,0)
I'm unsure how to implement this same logic, but give me multiple column numbers if ThisHeader exists in multiple columns.
I'm not particular about how the result is displayed, although ideally I'd use something like: =SUBSTITUTE(ADDRESS(1,col_number,4),"1","") after the column numbers are retrieved in order to translate to a letter format. perhaps with a comma or dash separating each number/column letter. I could add or use multiple formulas and columns rather than a nested formula as well if that is the best or only route.
Thanks in advance!
If you have O365, you can use:
=AGGREGATE(15,6,1/($1:$1="ThisHeader")*COLUMN($1:$1),SEQUENCE(COUNTIF($1:$1,"ThisHeader")))
If you do not have the SEQUENCE function, you can replace it and use:
=AGGREGATE(15,6,1/($1:$1="ThisHeader")*COLUMN($1:$1),ROW(INDEX($A:$A,1):INDEX($A:$A,COUNTIF($1:$1,"ThisHeader"))))
Results
The formula returns an array of the column numbers. So, to visualize them if you don't have the dynamic array feature of recent Excel versions, you may have to enter this as an array formula (with ctrl+shift+enter over multiple cells. Or by using an INDEX function to return each element.
I want to sum values in a row, but only for specific column numbers (or headers) which are listed elsewhere and are not constant.
It might be some range, or even better one cell with array containing column numbers. In either case not whole range or array will be always fully populated.
Is this even possible without using VBA?
If there's no way to avoid VBA I can give it a shot.
You may try the following:
Formula in H8:
=SUMPRODUCT((COLUMN($B8:$G8)=H$2:H$5+1)*$B8:$G8)
It's actually simple in this case since the second array is already transposed. Keep that in mind if you want to do this in any other way.
What I'm wanting to do is have a formula in one cell that counts the values in a range that conform to a lookup of that range cell's value compared to another cell.
OMG, now that I look at it, that is totally confusing. Let me try to clarify a lot here.
Say we have Cell1, which will hold the counting formula. I have a list of values in a two-column table, Table1. The range, Range1 that Cell1 will be counting from is a range of cells that have List Validation in them. Table1 holds references to all values that can result from those Lists, in column 1. I have another cell, Cell2, which holds a number value. Column 2 of Table1 holds values that reference Cell2. I need to count the number of values from Range1 whose row matches in Table12 match the value in Cell2. Is there a way I can do this with COUNTIF without referencing each cell individually? Is there some shorthand (like Range.currentValue) that I can use to get the value of the cell currently being checked? The range is 11 rows long, and I need to do a second range that has 12 rows counted.
Man, I really don't know how to clarify that any more... I'll post this for now, in case anyone can understand what I'm saying and knows the answer, while I work on a sample spreadsheet I can upload.
I did my best to visually represent what I'm trying to accomplish:
http://gyazo.com/b83295baf3b156683a5c39b40c806504
Extended explanation: http://gyazo.com/4048802050e3dcfca7aee238acc2f7dd
Use a helper column, say, between the brown and the first blue or at the right of the setup. Use a vlookup like
=vlookup(brownvalue,BluetableRange,2,false)
Then do a countif on the helper column
=countif(HelperColumn,"<="&GreenCellAddress)
You can hide the column with the helper if it upsets your spreadsheet design.
You can (and probably should) use a helper column as Teylyn suggests. But, for when that may be inconvenient, you can also use an array formula:
=SUM(COUNTIFS(listlookupcolumn,rangeoflists,numbervaluecolumn,"<="&numbertomatch))
To enter it as an array formula, type "ctrl-shift-enter" after editing the formula, rather than just "enter"
Rough explanation: since rangeoflists is in a place where a single value is expected, the countifs is calculated once for each value, and the array of results is passed to sum. Use the "evaluate formula" feature to see the intermediate result array.
Afterthought: It occurs to me now that this does rely on listlookupcolumn containing unique values. (Almost certainly true in this example.) You can modify the formula a bit to get around this:
=SUM(SIGN(COUNTIFS(listlookupcolumn,rangeoflists,numbervaluecolumn,"<="&numbertomatch)))
The SIGN function will keep you from double counting.
Again, you must use "ctrl-shift-enter" for this to work. (Yes, as I'm sure others are ready to point out, you can also use the sumproduct hack in this instance.)
I want to Vlookup using two criteria:
the value in Column D;
The amount in Column A and Column G which can be approximately matched.
The normal Vlookup only returns the value of the first row, so one solution I think about is to match both the Invoice Number and Approximately Match the amount.
I am not sure if it is the best solution, please advise a better one, not necessarily in VBA, it can also use INDEX or MATCH functions, etc.
Thanks a lot in advance!
Below is the formula I've been trying, it is like something If true, then this value, if false then Lookup the next one.... But I am still thinking about how to navigate though the Vlookup to search next value, do I need to use VBA to solve this?! Vlookup based on Multiple Criteria2
The following formula should work:
=INDEX(G3:G5,SUMPRODUCT(MAX((D3:D5=B3)*ROW(D3:D5)))-3,1)
That's just a fancier version of Index(Match) that is used as a common replacement for vlookup. In this case, instead of Match we use Sumproduct to get the max row with the criteria we are looking for.
ADDED: Added a -3 to the second paramater of INDEX in order to adjust the Row() returned to the actual range that is being Indexed.