Formula to stack rows under each other

Malcolm torishi

Board Regular
Joined
Apr 26, 2013
Messages
219
Hi I’ve been thinking of a way to stack rows of text and numbers under each other but I just can’t get it. Can anyone help with the following :-
I have an index column say A7:A27, persons name column B7:B27,and a time column C2:C27. Each of these rows can be filled with text and numbers and some of the rows can be completely empty, so eg filled rows could be rows 9,14,18, and 20 with the rest being empty. What I am looking to do next but just don’t know how is to take all of the complete 4 rows that are filled with data and stack them under each other starting with the earliest time first in column say G7, so if I have 4 different times under column C , I what the complete row of data staked in time order from G7 down wards so that the latest time would be at the bottom of the stack
if anyone can help thank you
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
I'm assuming you want the three columns listed (Index, Name and Time) so here's my solution with some sample data:

ABCDEFGHI
1IndexNameTime
2X12Bert0:35
3Z99Susan22:33
4X23Vanessa0:35
5
6IndexNameTime Sorted
7Z78Brandi22:45X23Vanessa0:35
8X12Xavier22:11X12Bert0:35
9X23Brandi1:00
10Z99Roger1:00
11W98John2:30X12Charlie1:00
12W98John2:30
13X34Alf16:25
14X12Charlie1:00Z77Xavier17:00
15Z99Roger1:00X12Xavier22:11
16X23Brandi1:00Z99Susan22:33
17Z77Xavier17:00Z78Brandi22:45
18X34Alf16:25

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
MT1

Worksheet Formulas
CellFormula
G7=IF(ROW()-ROW($G$6)-COUNTA($C$2:$C$27) > 0,"",INDEX(A$2:A$27,AGGREGATE(15,6,ROW($C$2:$C$27)-ROW($C$1)/($C$2:$C$27=I7),COUNTIF($I7:$I$26,I7))))
H7
=IF(ROW()-ROW($H$6)-COUNTA($C$2:$C$27) > 0,"",INDEX($B$2:$B$27,AGGREGATE(15,6,ROW($C$2:$C$27)-ROW($C$1)/($C$2:$C$27=I7),COUNTIF($I7:$I$26,I7))))
I7
=IF(COUNTA($C$2:$C$27) < ROW()-ROW($I$6),"",AGGREGATE(15,6,$C$2:$C$27,ROW()-ROW($I$6)))

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>
 
Upvote 0
Using the same sample data as Toadstool, but with simplified formulas.

In G7, copied right to H7 then filled down
Code:
=IF($I7="","",INDEX(A:A,AGGREGATE(14,6,ROW(A$2:A$27)/($C$2:$C$27=$M7),COUNTIF($M$7:$M7,$M7))))
In I7, filled down
Code:
=IFERROR(SMALL(C$2:C$27,ROWS(I$7:I7)),"")
If there are never duplicates in the index column (column A) then the formula in H7 could be further simplified to
Code:
=IF($I7="","",INDEX($B$2:$B$27,MATCH(G7,$A$2:$A$27,0)))
 
Upvote 0
Using the same sample data as Toadstool, but with simplified formulas.

In G7, copied right to H7 then filled down
Code:
=IF($I7="","",INDEX(A:A,AGGREGATE(14,6,ROW(A$2:A$27)/($C$2:$C$27=$M7),COUNTIF($M$7:$M7,$M7))))[/QUOTE]

Jason, Where does the M7 come from?
 
Upvote 0
Jason, Where does the M7 come from?
Oops!
M7 should have been I7, I copied your sample to a blank sheet, then moved your results right by 4 columns, your times were in column M, mine in column I.
Code:
=IF($I7="","",INDEX(A:A,AGGREGATE(14,6,ROW(A$2:A$27)/($C$2:$C$27=$I7),COUNTIF($I$7:$I7,$I7))))
 
Upvote 0
based on example from post#2 and with PowerQuery

Code:
[SIZE=1]// Table1
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    RBR = Table.SelectRows(Table.TransformColumnTypes(Source,{{"Time", type time}}), each not List.IsEmpty(List.RemoveMatchingItems(Record.FieldValues(_), {"", null}))),
    Sort = Table.Sort(RBR,{{"Time", Order.Ascending}, {"Name", Order.Ascending}, {"Index", Order.Ascending}})
in
    Sort[/SIZE]

Table1
IndexNameTimeIndexNameTime
X12Bert
00:35​
X12Bert
00:35​
Z99Susan
22:33​
X23Vanessa
00:35​
X23Vanessa
00:35​
X23Brandi
01:00​
X12Charlie
01:00​
Z99Roger
01:00​
Z78Brandi
22:45​
W98John
02:30​
X12Xavier
22:11​
X34Alf
16:25​
Z77Xavier
17:00​
X12Xavier
22:11​
W98John
02:30​
Z99Susan
22:33​
Z78Brandi
22:45​
X12Charlie
01:00​
Z99Roger
01:00​
X23Brandi
01:00​
Z77Xavier
17:00​
X34Alf
16:25​
 
Upvote 0
based on example from post#2 and with PowerQuery

Code:
[SIZE=1]// Table1
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    RBR = Table.SelectRows(Table.TransformColumnTypes(Source,{{"Time", type time}}), each not List.IsEmpty(List.RemoveMatchingItems(Record.FieldValues(_), {"", null}))),
    Sort = Table.Sort(RBR,{{"Time", Order.Ascending}, {"Name", Order.Ascending}, {"Index", Order.Ascending}})
in
    Sort[/SIZE]

Table1
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]Index[/COLOR][COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]Name[/COLOR][COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]Time[/COLOR][COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]Index[/COLOR][COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]Name[/COLOR][COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]Time[/COLOR]
X12Bert
00:35​
X12Bert
00:35​
Z99Susan
22:33​
X23Vanessa
00:35​
X23Vanessa
00:35​
X23Brandi
01:00​
X12Charlie
01:00​
Z99Roger
01:00​
Z78Brandi
22:45​
W98John
02:30​
X12Xavier
22:11​
X34Alf
16:25​
Z77Xavier
17:00​
X12Xavier
22:11​
W98John
02:30​
Z99Susan
22:33​
Z78Brandi
22:45​
X12Charlie
01:00​
Z99Roger
01:00​
X23Brandi
01:00​
Z77Xavier
17:00​
X34Alf
16:25​

<tbody>
</tbody>
Thank you everyone, you make it look so easy
 
Upvote 0

Forum statistics

Threads
1,214,375
Messages
6,119,165
Members
448,870
Latest member
max_pedreira

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top