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

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.

Related

counting number of cells in same row of two data ranges/columns with identical values. Excel

I would like to count how often a number (>0) appears in the same row of both columns 1 and 2.
I.e. in the below example the answer should be 1 for value 19 in both cells A11 and B11 (but should ignore value 8 in cells A8 and B9).
I tried these formulas:
=COUNTIF(A11, "=" & B11) works for single cells, but extending it to =COUNTIF(A2:A18, "=" & B2:B18) returns 0 (Error message 'Formula omits adjacent cells).
I also tried =COUNTIF(A2:A18, "= B2:B18") which also returns 0. (Here B2:B18 is not recognised as a range).
column 1 column 2
0 0
0 0
X X
6 X
6 14
7 X
8 X
12 8
16 X
19 19
21 16
29 16
31 13
36 23
94 58
189 104
193 112
I am using Office Professional Plus 2016.
Try this:
=SUMPRODUCT((A2:A18=B2:B18)*(A2:A18>0)*ISNUMBER(A2:A18))
Here, I am checking three conditions. (1) cells are equal (2) cell value is greater than zero and (3) cell value is a number. Change ranges in formula as required.
See image for reference:

How to look up for multiple values and convert them in to a horizontal table in excel

I have a table like below in excel spread sheet
A 1
A 2
B 12
B 4
B 56
B 68
C 7
C 8
C 34
D 10
D 11
i need to convert the table as below
First entry Second entry Third entry Fourth entry
A 1 2 - -
B 12 4 56 68
C 7 8 34
D 10 11
Provided your list of letters (assumed to be in ColumnA starting in Row1) is sorted and you have a separate list of just one each of those letters (say starting in D1) then a formula may achieve the results you want:
=IF(COUNTIF($A:$A,$D1)>COLUMN()-5,OFFSET(INDEX($A:$A,MATCH($D1,$A:$A,0)),COLUMN()-5,1),"")
In F1, copied down to suit and then all formulae copied across until an entire column is blank.

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

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 :)

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