In new Google Sheets there is no need for a function. Just select B
and C
, Ctrl+c, select the cell immediately to the right of A
and Edit, Paste special, Paste transpose.
This creates copies of B
and C
but there is no linkage so those below A
may be deleted without affect those to the right of A
.
Short answer
The desired result could be obtained without scripting and this is recommended for cases where number of cells is small, especially if the OP don't know about scripting. To do so,
- Add auxiliary columns for each sorting criteria
- Then use the SORT() or QUERY() functions.
Extended answer
Google Sheets has some additional functions regarding those available in other spreadsheet applications. Two of them are SORT() and QUERY() which allow to get the desired result without scripting.
As QUERY() return a blank cell for those containing ?
as value, the SORT() function will be used.
Original data
Assume that the original data is in A2:D13
.
Auxiliary columns
Auxiliary columns will be used for sorting. Only one aggregate function is presented in order to keep the answer short.
Add the following formulas and fill down until the last row of the source data.
D2: =Row(C2)-Row($C$2)+1
E2: =ISERROR(LOOKUP("?",OFFSET($A$2,MATCH(A2,$A$2:$A$13,0)-1,2,COUNTIF($A$2:$A$13,A2))))
F2: =AVERAGEIF($A$2:$A$13,A2,$C$2:$C$13)
If you find helpful having column headers, add them to the row 1.
Key Formula
G2: =ARRAY_CONSTRAIN(SORT(A2:F13,5,TRUE(),6,TRUE(),1,TRUE()),12,3)
ARRAY_CONSTRAIN
is included to limit the result to the columns of the source data.
Best Answer
say you want to go from C5 all the way through C100:
will work in both Excel and Google Sheets.