Sorting row by row - excel

I have a table in excel which has values like below
2 1 3
6 5 4
7 2 3
Considering the rows do not have a column header, what is the easiest way to sort them row by row, such that I get the below output
1 2 3
4 5 6
2 3 7

If the array starts in A1 please try (UNTESTED) in AB1 copied across 27 columns and down to suit:
=SMALL($A1:$AA1,COLUMN()-27)

Related

Excel formula to return last xth numeric value from row

I have a data set like this:
a 1 2 3 5 6 7
b 5 1 3 4
c 7 4 3 2 6
d 1 2 3 7
e 7 5 5 6 7
which i want to transform in excel to only show the last 4 numeric values for each row, i.e.
a 3 5 6 7
b 5 1 3 4
c 4 3 2 6
d 1 2 3 7
e 5 5 6 7
Ive managed to use =INDEX(row1,MATCH(9.99999999999999E+307,row1)) which correctly returns the last value (i.e. 7 for row1 in this case) but how could i get the 2nd last, 3rd last, 4th last etc?
With a in A1, in M1 copied across and down to suit:
=MID(RIGHT($B1&$C1&$D1&$E1&$F1&$G1&$H1&$I1&$J1,4),COLUMN()-12,1)
then hide ColumnsB:L.
(Only works for single digits, as shown. Recent versions of Excel may offer better options.)
So I managed to figure out how to do this generically for any digits:
Say your original numerical data is in cells D5:N9.
OPTIONAL:
If any of the rows of data contain the same value twice create a copy in cells D13:N17 which amends duplicates slightly by using in D13 and dragging to fill
=IF(D5="","",D5+0.0001*(COUNTIF($D5:D5,D5)-1))
Then in cells A13:A17 enter values 13,14,15,16,17
and in cells A20:A29 enter values D, E, F, G, H, I, J, K, L, M
In Cell D20 you can return the last from row 13 value using:
=LOOKUP(9.99999999E+307,D13:N13)
and copy this down for each row.
In Cell E20 you can return the 2nd last entry using
=LOOKUP(9.99999999E+307,$D13:INDIRECT(CONCATENATE(INDEX($A$20:$A$29,MATCH(D20,$D13:$N13,0)-1),$A13)))
and copy this down for each row and drag it across to H24 to fill in all the values for 3rd last, 4th last and 5th last for each row.

Sum across columns based on 3 criteria

I'm trying to get a Sumif working across multiple rows.
For example, say my data source is below:
A B C
1 1 10 11
2 2 9 12
3 3 8 13
4 4 7 14
5 5 6 58
I want to sum from Columns A to C, in row 3. Output would be 24.
Ideally my criteria for the Horizontal Start, Horizontal End and Vertical would all be referenced in different cells which can be updated to get a new result depending on the criteria.
Is this possible so that the criteria cells can be updated and the formula will update accordingly?
Use a SUMIF, and betweem the logical criteria, simply use 3 criterias by seperating each with "&"'. This says that excel will sum if a happens, and b and c.

Finding Value In Excel Based On Highest Value and Matching Value in Excel

I have three rows in an Excel sheet that I need to get values from. Row 1 are just set numbers, Row 2 is values, and Row 3 is another value with many having the same value. I need to first check for the highest value in Row 3, match it with the value in Row 2, get the highest value in Row 2 first if Row 3 is the same, and then report Row 1 as the answer.
1 2 3 4 5 6 7 8 9 10 11 12
15 16 17 18 19 20 21 22 23 24 25 26
4 4 2 1 5 7 4 3 1 5 3 3
So I want to have it output as:
6 10 5 7 2 1 12 11 8 3 9 4
I tried a few HLOOKUP values but nothing seems to be hooking. Any ideas?
For a formula answer use this array formula:
=INDEX($A$1:$L$1,MATCH(LARGE(($A$3:$L$3*10000)+$A$2:$L$2,COLUMN(A:A)),($A$3:$L$3*10000)+$A$2:$L$2,0))
Being an array formula it must be confirmed with Ctrl-Shift-Enter instead of Enter when exiting Edit mode. If done correctly then Excel will put {} around the formula.
So enter the formula in the first cell, hit Ctrl-Shift-Enter Then drag/Copy across the number of columns desired.

Summing a set of values based on cell content and row position

In the below table rows 2,3 and 4 have some details of a sporting event.
Range A2:C4 has a set of squad numbers and range D2:F4 has the details of who scored goals.
A B C D E F
1 Squad # Scorers
2 1 3 6 2 8 3
3 3 6 7 6 1
4 1 5 6 7 2 4
As an example squad # 6 has scored 8 goals based on the values equivalent position in the Squad section and relative to the Scorers range.
What formula will give me this total value and the equivalent total values for all squad numbers like the table below?
Some cells will be empty like F3.
1 9
3 14
5 2
6 8
7 0
A simple SUMPRODUCT function should take care of this.
=SUMPRODUCT($D$2:$F$4, --($A$2:$C$4=H2))
Fill down as necessary.
        
With only 3 games, the simplest way that I can see to do this would be to use 4 SUMIFS statements, as follows [assumes that your results data is in columns A & B, starting at row 5 and moving down; A5:A12 would hold the IDs for the different squads, and this formula would go in B5 and be copied down]:
=SUMIFS($D$2:$F$2,$A$2:$C$2,A5)+SUMIFS($D$3:$F$3,$A$3:$C$3,A5)+SUMIFS($D$4:$F$4,$A$4:$C$4,A5)
What it does is sum columns D:F, for row 1, row 2, and row 3, based on the fact that columns A:C for those rows match the appropriate squad ID.
This would be possible with an arguably shorter but more complex Array Formula, but with the data as you've presented it, I feel this is the clearest method.

Return list of matching rows

Sheet1
A B C D
1 2 3 4
2 4 5 6
3 3 5 6
4 7 3 1
5 4 6 7
Sheet 2
A B C D
1 4
2 1
3 1 3 4
4 1 2 5
5 2 3
6 2 3 5
7 4 5
Column A of Sheet 2 has a non repeating listing of all values in Sheet 1. I would like a forumla so Col B of Sheet 2 lists the value of Sheet 1 Col A for each row where the Sheet 2 Col A lookup value is found. Either giving me a comma sep list or putting the results in sheet 2 Col B,C,D,...
I came up with a solution, but it involves a handful of formulas, not just one. Hopefully, you will still find it useful.
Your Sheet2 would basically look like this:
Here are the formulas you need to enter:
B1: =IFERROR(SMALL($G4:$U4,COLUMN()-1),"") [drag down and across to D7]
G1: =IF(F2=$W2,F1+1,MAX(1,F1)) [drag across to U1]
G2: =IF(F2=$W2,1,F2+1) [drag across to U2]
G3: =INDEX(Sheet1!B$1:D$5,G1,G2) [drag across to U3]
G4: =IF(G$3=$F4,G$1,"") [drag down and across to U10]
What this does is organize the Sheet1 data into rows, where each row corresponds to a lookup value. Then, it grabs the smallest value, the second smallest value (if one exists), and third smallest value (if one exists) from each row.
This should be easy to scale to as large a spreadsheet as you need (as long as you don't run out of columns).

Resources