Stacked multiple columns into one column ignoring blank and 0

ceecee88

Board Regular
Joined
Jun 30, 2022
Messages
59
Office Version
  1. 365
  2. 2013
Platform
  1. Windows
Hi, this what I have got so far, I get it to stacked but it won't ignore blank (it is showing 0), I need it for older version, any suggestion please?

Thank you!

1656929172789.png
 
When you are saying I could use 10 in this example because there is only less than 10 results?
With 10, the formula can accommodate a maximum of 10 rows.

Here's 12 rows, showing how the formula (using 10) starts to break:

ABCDEFGHI
1
21AAFF
32BBGG
43DD
54CC
65
76
87
98
109
1110
1211
1312EE
14
15AA
16BB
17CC
18DD
19FF
20GG
21GG
22
23Stack
24by columnExplain
2511FALSEFALSE41111AA
2612FALSEFALSE42212BB
27FALSE23FALSEFALSE314CC
2814FALSEFALSEFALSE423DD
29FALSEFALSEFALSEFALSE541FF
30FALSEFALSEFALSEFALSE642GG
31FALSEFALSEFALSEFALSE742GG
32FALSEFALSEFALSEFALSE
33FALSEFALSEFALSEFALSE
34FALSEFALSEFALSEFALSE
35FALSEFALSEFALSEFALSE
36FALSEFALSE42FALSE
Sheet1
Cell Formulas
RangeFormula
B15:B21B15=IFERROR(INDEX(MyData,MOD(SMALL(IF(LEN(MyData),1+ROW(MyData)-MIN(ROW(MyData))+10*(1+COLUMN(MyData)-MIN(COLUMN(MyData)))),ROWS(B$15:B15)),10),INT(SMALL(IF(LEN(MyData),1+ROW(MyData)-MIN(ROW(MyData))+10*(1+COLUMN(MyData)-MIN(COLUMN(MyData)))),ROWS(B$15:B15))/10)),"")
B25:E36B25=IF(LEN(MyData),1+ROW(MyData)-MIN(ROW(MyData))+10*(1+COLUMN(MyData)-MIN(COLUMN(MyData))))
H25:H31H25=SMALL(B$25#,G25)
I25:I31I25=INDEX(MyData,MOD(H25,10),INT(H25/10))
Dynamic array formulas.
Named Ranges
NameRefers ToCells
MyData=Sheet3!$B$2:$E$13B25, I25:I31, B15:B21
 
Upvote 0

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Does the order matter? If not, this is somewhat less 'horrible' than Stephen's and should also work in 2010.

22 07 05.xlsm
ABCDE
1
2AAFF
3BBGG
4DD
5CCEE
6
7
8AA
9FF
10BB
11GG
12DD
13CC
14EE
15 
16 
To Column
Cell Formulas
RangeFormula
B8:B16B8=IFERROR(INDIRECT(TEXT(AGGREGATE(15,6,(ROW(B$2:E$5)*10^6+COLUMN(B$2:E$5))/(B$2:E$5<>""),ROWS(B$8:B8)),"R000000C000000"),0),"")
May I ask what is the 10^6 and R000000C000000? If I understand it I'll be able to adjust accordingly in the future. Thank you!
 
Upvote 0
With 10, the formula can accommodate a maximum of 10 rows.

Here's 12 rows, showing how the formula (using 10) starts to break:

ABCDEFGHI
1
21AAFF
32BBGG
43DD
54CC
65
76
87
98
109
1110
1211
1312EE
14
15AA
16BB
17CC
18DD
19FF
20GG
21GG
22
23Stack
24by columnExplain
2511FALSEFALSE41111AA
2612FALSEFALSE42212BB
27FALSE23FALSEFALSE314CC
2814FALSEFALSEFALSE423DD
29FALSEFALSEFALSEFALSE541FF
30FALSEFALSEFALSEFALSE642GG
31FALSEFALSEFALSEFALSE742GG
32FALSEFALSEFALSEFALSE
33FALSEFALSEFALSEFALSE
34FALSEFALSEFALSEFALSE
35FALSEFALSEFALSEFALSE
36FALSEFALSE42FALSE
Sheet1
Cell Formulas
RangeFormula
B15:B21B15=IFERROR(INDEX(MyData,MOD(SMALL(IF(LEN(MyData),1+ROW(MyData)-MIN(ROW(MyData))+10*(1+COLUMN(MyData)-MIN(COLUMN(MyData)))),ROWS(B$15:B15)),10),INT(SMALL(IF(LEN(MyData),1+ROW(MyData)-MIN(ROW(MyData))+10*(1+COLUMN(MyData)-MIN(COLUMN(MyData)))),ROWS(B$15:B15))/10)),"")
B25:E36B25=IF(LEN(MyData),1+ROW(MyData)-MIN(ROW(MyData))+10*(1+COLUMN(MyData)-MIN(COLUMN(MyData))))
H25:H31H25=SMALL(B$25#,G25)
I25:I31I25=INDEX(MyData,MOD(H25,10),INT(H25/10))
Dynamic array formulas.
Named Ranges
NameRefers ToCells
MyData=Sheet3!$B$2:$E$13B25, I25:I31, B15:B21
I see, thank you so much! I really appreciate your time.
 
Upvote 0
May I ask what is the 10^6 and R000000C000000?
10^6 multiplies the row number by 1 million so that it is separated from the column number when that is added.
R000000C000000 is the R1C1 notation to be used in the INDIRECT function, allowing for the fact that the row numbers were multiplied by 1 million.
See here for more on INDIRECT function

The formula is not an easy one to explain.
 
Upvote 0
May I ask what is the 10^6 and R000000C000000? If I understand it I'll be able to adjust accordingly in the future. Thank you!
I tried it and got #VALUE!, my actual data has 60 columns and 150 rows, don't know if that has anything to do with the error or not. Thank you!
 
Upvote 0
I tried it and got #VALUE!, my actual data has 60 columns and 150 rows, don't know if that has anything to do with the error or not. Thank you!
What is the actual range that your data is in?
What is the adjusted formula that you used?
What cell is the first formula in?
 
Upvote 0
What is the actual range that your data is in?
What is the adjusted formula that you used?
What cell is the first formula in?
I test it if the data and the output is in the same sheet then it work perfectly! But in this case, they are in a different sheet may be that's why it showing 0? My apology for not having this information previously.
 
Upvote 0
If they are on different sheets then you need to include the sheet name in the references and the INDIRECT function. Here is a small example.

ceecee88.xlsm
ABCDEF
1
2AAFF
3BBGG
4DD
5CCEE
6
Sheet 3


ceecee88.xlsm
A
1
2AA
3FF
4BB
5GG
6DD
7CC
8EE
9 
10 
Sheet 2
Cell Formulas
RangeFormula
A2:A10A2=IFERROR(INDIRECT("'Sheet 3'!"&TEXT(AGGREGATE(15,6,(ROW('Sheet 3'!B$2:E$5)*10^6+COLUMN('Sheet 3'!B$2:E$5))/('Sheet 3'!B$2:E$5<>""),ROWS(A$2:A2)),"R000000C000000"),0),"")
 
Upvote 0
If they are on different sheets then you need to include the sheet name in the references and the INDIRECT function. Here is a small example.

ceecee88.xlsm
ABCDEF
1
2AAFF
3BBGG
4DD
5CCEE
6
Sheet 3


ceecee88.xlsm
A
1
2AA
3FF
4BB
5GG
6DD
7CC
8EE
9 
10 
Sheet 2
Cell Formulas
RangeFormula
A2:A10A2=IFERROR(INDIRECT("'Sheet 3'!"&TEXT(AGGREGATE(15,6,(ROW('Sheet 3'!B$2:E$5)*10^6+COLUMN('Sheet 3'!B$2:E$5))/('Sheet 3'!B$2:E$5<>""),ROWS(A$2:A2)),"R000000C000000"),0),"")
It work now! but it's going to the right and then down. How do I make it going down first then next column? Thank you!
 
Upvote 0
Does the order matter? If not, this is somewhat less 'horrible' than Stephen's and should also work in 2010.
Very nice!

But I can't resist the slightly more horrible version that stacks by column ...

ABCDE
1
2AAFF
3BBGG
4DD
5CCEE
6
7
8AAAA
9FFBB
10BBCC
11GGDD
12DDEE
13CCFF
14EEGG
15  
16
Sheet1
Cell Formulas
RangeFormula
B8:B15B8=IFERROR(INDIRECT(TEXT(AGGREGATE(15,6,(ROW(B$2:E$5)*10^6+COLUMN(B$2:E$5))/(B$2:E$5<>""),ROWS(B$8:B8)),"R000000C000000"),0),"")
C8:C15C8=IFERROR(INDIRECT(TEXT(SUMPRODUCT(MID(TEXT(AGGREGATE(15,6,(COLUMN(B$2:E$5)*1000+ROW(B$2:E$5))/(B$2:E$5<>""),ROWS(C$8:C8)),"000000"),{4,1},3)*{1000,1}),"R000C000"),),"")
 
Upvote 0
Solution

Forum statistics

Threads
1,223,737
Messages
6,174,206
Members
452,551
Latest member
croud

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