Index/Match values from a column using a grid of a different length (Excel 2010) - excel

I am trying to index match values from a long column to a grid of a different length. It looks like this
Word Number Column X Column Y Column Z
This 55 55 33 12
is 62 62 42 18
The 78 78 31 24
42
31
12
18
24
33
The grid (Column X,Y,Z) contains all the values from the Number Column. What I am trying to do is basically index the "Word" column, using a value from the "Number" Column, and looking it up in the value array of X Y Z.
Example (because this is confusing):
Input the Value 33 from the Number column, look for the value in the columns XYZ, and then return the Word "This".
Input the Value 18 from the number column, look for the value in columns XYZ, return the word "is"
etc...
Any help would be very much appreciated!

there is a quicker way and shorter formula to do this:
=IFERROR(INDEX(A:A,IFERROR(MATCH(B2,C:C,0),IFERROR(MATCH(B2,D:D,0),MATCH(B2,E:E,0))),1),"not found")
paste that into, any column really, into row 2 and drag down, it will return the words you require, if value not found it will return "not found"

Here is your spreadsheet starting at cell A1 (without your headers):
A B C D E
1 This 55 55 33 12
2 is 62 62 42 18
3 The 78 45 31 24
4 42
5 31
6 12
7 18
8 24
9 33
10
11 Input: 24
12 Output: The
Copy this into cell C10, and drag the formula across to cell E10:
=IF(ISERROR(IF(ISERROR(IF(ISERROR(MATCH($B$11,C1:C3,0)),"",CONCATENATE("A",MATCH($B$11,C1:C3,0)))),"",INDIRECT(IF(ISERROR(MATCH($B$11,C1:C3,0)),"",CONCATENATE("A",MATCH($B$11,C1:C3,0)))))),"",IF(ISERROR(IF(ISERROR(MATCH($B$11,C1:C3,0)),"",CONCATENATE("A",MATCH($B$11,C1:C3,0)))),"",INDIRECT(IF(ISERROR(MATCH($B$11,C1:C3,0)),"",CONCATENATE("A",MATCH($B$11,C1:C3,0))))))
Copy this to the "output" cell B12 and use cell B11 as your "input":
=CONCATENATE(C10,D10,E10)
VIOLA!!! You're done!
Proof:
The MATCH() function will look for your value in an array (the range). If it finds it, it returns the index of that array (indexed at 1), otherwise it throws an error. Be sure to set the 3rd argument to "0" so that it only looks for EXACT matches.
Paste this into C14:
=MATCH($B$11,C1:C3,0)
Next, we check if the MATCH() function did indeed throw an error. Paste this into C15:
=IF(ISERROR(C14),"",C14)
Now we have the row number of our matched value, so we will use the CONCATENATE() function to join it to our "word column", A, for use in the next step. Paste this into C16:
=CONCATENATE("A",C15)
Using that string from above, use the INDIRECT() function to turn it into an actual cell reference. Paste this into C17:
=INDIRECT(C16)
And finally, check if a legitimate cell reference was created. If so, return the word, otherwise return "". Paste this into C18:
=IF(ISERROR(C17),"",C17)
Lastly, drag the formulas from C14:C18 to E14:E18, and concatenate the results. The cells in row 18 should match the cells in row 10.
Hope this helps :)

Related

Match row and column to get the value from the same row - Matrix

I have a matrix like below,
A B C D E F
A 0 12 13 14 15 16
B 12 0 12 15 15 18
C 11 11 0 12 12 15
D 26 24 25 0 22 25
E 87 86 82 12 0 23
F 11 25 36 14 25 0
Now i want that in the below format,
A A 0
A B 12
A C 13
A D 14
A E 15
A F 16
B A 12
B B 0
B C 12 so on.
How can i achive that in excel via formulae.
As stated Offset is a volatile function in that it will always calculate whenever excel calculates regardless if the underlying data has changed or not.
Index is not volatile:
In A10:
=INDEX($A$2:$A$7,INT((ROW(1:1)-1)/ROWS($A$2:$A$7))+1)
In B10:
=INDEX($B$1:$G$1,MOD((ROW(1:1)-1),COLUMNS($B$1:$G$1))+1)
In C10:
=INDEX(A:G,MATCH(A10,$A:$A,0),MATCH(B10,$1:$1,0))
Then copy down
Assuming your data is fixed width (6 here) and exists in columns A-F. Put the following formulas in J1-L1 and fill down. It uses the offset method and looks at fractions of the row, either the remainder or the integer to determine steps for rows (integer) or remainder via mod function (columns).
=OFFSET($A$1,ROUNDDOWN((ROW(J1)-ROW($J$1))/6,0)+1,0)
=OFFSET($A$1,0,MOD((ROW(K1)-ROW($J$1)),6)+1)
=OFFSET($A$1,ROUNDDOWN((ROW(L1)-ROW($J$1))/6,0)+1,MOD((ROW(K1)-ROW($J$1)),6)+1)
I'm hoping I understand your question. But, assuming you had your matrix starting in the top left of the sheet, you would have:
Going Down:
"A" in cell A2, "B" in cell B2, etc
Going Across:
"A" in cell B1, "B" in cell C1, etc
Data:
Your first value (corresponding to A,A) in cell B2
So, now you havem for example, in cell A10 the row letter you want and, in cell A11 the column letter you want. So, you could use the following formula to get your desired result:
=INDEX($B$2:$G$7,MATCH(A10,$A$2:$A$7,0),MATCH(B10,$B$1:$G$1,0))
Basically, using the INDEX() function on your array and matching the row to the desired row letter and the column to your desired column letter.
Hope that makes sense.

How to use index and match concept to retrieve values from 2nd row and 3rd column or 1st row and 4th column and so on

Jan Feb Mar Apr May
1 10 110 101 11 90
2 20 111 102 12 91
3 30 112 103 13 92
4 40 113 104 14 93
5 50 114 105 15 94
How to use index and match concept to retrieve values from 2nd row and 3rd column or 1st row and 4th column and so on
If you wanted to match cell $B$2 (Row 2, Column "February") you could use the following formula:
INDEX(B1:B5, MATCH(91, E1:E5, 0))
This would give the value 111, which is the value of $B$2
The INDEX function in Excel takes a range (B1:B5) and an index into that range, and returns the value. In an INDEX MATCH, the index used is actually a call to the MATCH function. Here, I obtained an index of 2 when MATCHing the value 91 in the range E1:E5.
In English you might read this call as saying "Find the value in the range B1 to B5 whose index is the same as the value 91 in the range E1 to E5."
If the months are in B1:F1, row labels in A2:A6 and main body of the table in B2:F6 then you can get the value at the intersection of the nth row and kth column of B2:F6 using this formula
=INDEX(B2:F6,n,k)
As per Tim's answer you can derive the n and k values using MATCH functions based on the values in the column headers and row labels, e.g. matching "Apr" and 4 will give you the value at the intersection, i.e. 14
and the formula would look like this
=INDEX(B2:F6,MATCH(4,A2:A6,0),MATCH("feb",B1:F1,0))
see here for more

Extract numbers from excel table

I have a Excel table with 5 columns filled with numbers, for e.g.
A1 B1 C1 D1 E1
4 12 23 37 41
1 4 19 25 45
4 20 25 31 44
I want to find the exact place (ROW,COLUMN) for each number.
In K1:
=COUNTIF($A$1:$E$3,H1)
where for e.g. H1=4 the result is 3
In (L1,M1,N1):
=SMALL(IF($A$1:$E$3=$H$1,ROW($A$1:$E$3)-ROW($A$1)+1),COLUMNS($L1:L1))
with Ctrl-Shift-Enter and the result is L1=1,M1=2,N1=3
Now I want to find a formula which show me the COLUMN number. If I use in (L2,M2,N2)
=SMALL(IF($A$1:$E$3=$H$1,COLUMN($A$1:$E$3)-COLUMN($A$1)+1),COLUMNS($L2:L2))
with Ctrl-Shift-Enter I have as result L2=1,M2=1,N2=2 which is not that I want. The order must be L2=1,M2=2,N2=1.
I have stuck with this. I use office 2007.
You could use the results you got from the rows to get the columns maybe?
=MATCH($H$1,INDEX($A$1:$E$3,L1,0),0)
In L2, filled through to M2 gives you the results you are expecting. Note that this formula works only if the number you're looking for (here 4) appears only once in any given row.

Index & Match formula using IF and ISERROR

I have data in columns C & D. A range of ten students in A1 to A10 are identified with roll numbers. In Column C and corresponding Column D, there are 8 students from roll number 1 to 8 (Column C) and their marks (Column D).
I need a formula in column B to automatically extract the marks from column D against the roll numbers in Column A and the two cells in column B (marks of roll number 9 & 10) may remain blank.
Any Excel formula or VBA macro solution is much appreciated.
Column-A Column-B Column-C Column-D
1 50 1 50
2 55 2 55
3 35 3 35
4 60 4 60
5 78 5 78
6 45 6 45
7 39 7 39
8 82 8 82
9
10
Try using VLOOKUP with IFERROR, i.e. this formula in B2 copied down
=IFERROR(VLOOKUP(A2,C$2:D$9,2,0),"")
VLOOKUP will return the required marks when the roll number exists.....or an error which IFERRORconverts to a blank.
The simplest solution would seem to be copy and paste. Alternative solutions would seem to be relatively simple (eg #barry's) but if you really want INDEX, MATCH, IF and ISERROR then maybe:
=IF(ISERROR(INDEX(D:D,MATCH(A2,C:C,0))),"",INDEX(D:D,MATCH(A2,C:C,0)))

formula for finding the first non-empty cell

I have a spreadsheet with 2 columns of data, column A and B, and column C where I'm looking for the formula.
row A B C
1 50
2
3
4
5 56 6
6
7
8 46 10
9
10
11 64 18
As you can see, a row either contains a value or not. In column C, I'm looking to calculate the difference between
a) the value in column B and the value in column A's first non-empty cell directly above (so for example, at row 5, I calculate the difference between B5 and A1 56 - 50 = 6) if the value of B is a number and
b) the value in column A and the value in column B's first non-empty cell directly above (row 8, 56 - 46 = 10)
and put nothing if neither column A and B are empty.
I've been struggling with "first non-empty cell" to write an R1C1 formula. Note that I know I can do this in VBA but I'm looking for the R1C1 formula.
Thanks for your help.
Here is an array formula (that you need to validate with Ctrl + Shift + Enter) you can put in C1 and drag and drop till the end of your data:
=IF(OR(A1<>"",B1<>""),INDEX($B$1:B1,MAX(IF($B$1:B1="",0,ROW($B$1:B1))))-INDEX($A$1:A1,MAX(IF($A$1:A1="",0,ROW($A$1:A1)))),"")
Or, in a french version of Excel:
=SI(OU(A1<>"";B1<>"");INDEX($B$1:B1;MAX(SI($B$1:B1="";0;LIGNE($B$1:B1))))-INDEX($A$1:A1;MAX(SI($A$1:A1="";0;LIGNE($A$1:A1))));"")
Note that if you feel interested, you can commit into Stackoverflow in french
Perhaps try this formula in C2 copied down
=IF(B2="",IF(A2="","",LOOKUP(9.99E+307,B$1:B1)-A2),B2-LOOKUP(9.99E+307,A$1:A1))

Resources