T_APPNAR

=T_APPNAR(na,hv)

na
integer, number of arrays
hv
string, only "h" or "v" for horizontal or vertical

T_APPNAR tool formula, a LAMBDA that writes other explicit LAMBDA for appending N arrays horizontally of vertically.

Xlambda

Well-known Member
Joined
Mar 8, 2021
Messages
832
Office Version
  1. 365
Platform
  1. Windows
T_APPNAR tool formula, a LAMBDA that writes other explicit LAMBDA for appending N arrays horizontally of vertically.
If the arrays we need to append are in different spreadsheets or are created inside other formulas, we can not use recursion to ease our task , we have to construct explicit formulas that fits particular scenarios.
Ex: Formula for appending 6 arrays vertically , we call T_APPNAR(6,"v")=LAMBDA(a1r,a2r,a3r,a4r,a5r,a6r,APPEND2V(APPEND2V(APPEND2V(APPEND2V(APPEND2V(a1r,a2r,),a3r,),a4r,),a5r,),a6r,))
OBS: You need to have already defined APPEND2V and APPEND2H, then you can define like APPEND6V(a1r,a2r,a3r,a4r,a5r,a6r) and reuse it any time you need it.
Note: personal syntax T_, comes from tool, means that are formulas instruments used for helping us on solving bigger picture tasks, like to write other formulas, patterns transformations, interfaces to ease complex conditional formatting formulas etc.
Excel Formula:
=LAMBDA(na,hv,
     LET(x,OR(hv={"h","v"}),
        a,"=LAMBDA(",b,REPT("a"&SEQUENCE(,na)&"r,",1),
        c,REPT("APPEND2"&UPPER(hv)&"(",SEQUENCE(,na-1,1,0)),
       d,"a1r",e,","&REPT("a"&SEQUENCE(,na-1,2)&"r,)",1),f,")",
       IF(x,CONCAT(a,b,c,d,e,f),"''h''or''v''only")
    )
)
LAMBDA 5.0.xlsm
ABCDEFGHI
1a1 - 1a1 - 2a2 - 1a2 - 2a4 - 1a4 - 2
2a1 - 3a1 - 4a2 - 3a2 - 4a4 - 3a4 - 4
3a1 - 5a1 - 6a2 - 5a2 - 6a4 - 5a4 - 6
4a1 - 7a1 - 8a2 - 7a2 - 8a4 - 7a4 - 8
5a1 - 9a1 - 10a2 - 9a2 - 10
6a1 - 11a1 - 12a2 - 11a2 - 12a5 - 1a5 - 2
7a1 - 13a1 - 14a5 - 3a5 - 4
8a1 - 15a1 - 16a3 - 1a3 - 2a5 - 5a5 - 6
9a1 - 17a1 - 18a3 - 3a3 - 4a5 - 7a5 - 8
10a1 - 19a1 - 20a3 - 5a3 - 6
11a1 - 21a1 - 22a3 - 7a3 - 8a6 - 1a6 - 2
12a1 - 23a1 - 24a3 - 9a3 - 10a6 - 3a6 - 4
13a3 - 11a3 - 12a6 - 5a6 - 6
14a6 - 7a6 - 8
15ex: append the arrays above all toghether,considering that are not in the same spreadsheet or are results of other array calculations
16that live inside a formula (we can not use APPENDNHV)
17
18get to a cell, call =T_APPNAR(3,"v"), the formula shows the string result =LAMBDA(a1r,a2r,a3r,APPEND2V(APPEND2V(a1r,a2r,),a3r,)) , copy the cell, paste in other cell as value, hit the F2, or click the cursor inside the cell, hit Enter, we will get a #CALC! error. Then, from the formula bar, copy the whole formula, hit escape, go to name manager , define APPEND3V, and thats it.Follow the same steps for APPEND3H. Now we can use them.
19
20=T_APPNAR(3,"v")=T_APPNAR(3,"h")
21=LAMBDA(a1r,a2r,a3r,APPEND2V(APPEND2V(a1r,a2r,),a3r,))=LAMBDA(a1r,a2r,a3r,APPEND2H(APPEND2H(a1r,a2r,),a3r,))
22
23=LAMBDA(a1r,a2r,a3r,APPEND2V(APPEND2V(a1r,a2r,),a3r,))=LAMBDA(a1r,a2r,a3r,APPEND2H(APPEND2H(a1r,a2r,),a3r,))
24#CALC!#CALC!
25
26=APPEND3H(A1#,APPEND2V(D1#,D8#,),APPEND3V(G1#,G6#,G11#))
27a1 - 1a1 - 2a2 - 1a2 - 2a4 - 1a4 - 2
28a1 - 3a1 - 4a2 - 3a2 - 4a4 - 3a4 - 4
29a1 - 5a1 - 6a2 - 5a2 - 6a4 - 5a4 - 6
30a1 - 7a1 - 8a2 - 7a2 - 8a4 - 7a4 - 8
31a1 - 9a1 - 10a2 - 9a2 - 10a5 - 1a5 - 2
32a1 - 11a1 - 12a2 - 11a2 - 12a5 - 3a5 - 4
33a1 - 13a1 - 14a3 - 1a3 - 2a5 - 5a5 - 6
34a1 - 15a1 - 16a3 - 3a3 - 4a5 - 7a5 - 8
35a1 - 17a1 - 18a3 - 5a3 - 6a6 - 1a6 - 2
36a1 - 19a1 - 20a3 - 7a3 - 8a6 - 3a6 - 4
37a1 - 21a1 - 22a3 - 9a3 - 10a6 - 5a6 - 6
38a1 - 23a1 - 24a3 - 11a3 - 12a6 - 7a6 - 8
39
40OBS: Both APPEND2V and ..2H need to have the trailing "," , the ..3V or ..3H don't need them
41NOTE: If you use this pattern extensivly it can be save as a LAMBDA also, especially for whatever pattern suits you nneds
42
T_APPNAR post
Cell Formulas
RangeFormula
A1:B12A1="a1 - "&SEQUENCE(12,2)
D1:E6D1="a2 - "&SEQUENCE(6,2)
G1:H4G1="a4 - "&SEQUENCE(4,2)
G6:H9G6="a5 - "&SEQUENCE(4,2)
D8:E13D8="a3 - "&SEQUENCE(6,2)
G11:H14G11="a6 - "&SEQUENCE(4,2)
A20,A26,A23,E23,E20A20=FORMULATEXT(A21)
A21A21=T_APPNAR(3,"v")
E21E21=T_APPNAR(3,"h")
A24A24=LAMBDA(a1r,a2r,a3r,APPEND2V(APPEND2V(a1r,a2r,),a3r,))
E24E24=LAMBDA(a1r,a2r,a3r,APPEND2H(APPEND2H(a1r,a2r,),a3r,))
A27:F38A27=APPEND3H(A1#,APPEND2V(D1#,D8#,),APPEND3V(G1#,G6#,G11#))
Dynamic array formulas.
 
Upvote 0
This is neat! Though I think it might get cumbersome if you need more and more arguments, you have to keep up with more and more functions.

Since your APPEND#X always have a blank i parameter, I modified your APPEND2V and APPEND2H like the below. These will allow you to provide a chain of single parameters, followed by a termination parameter; this is a trick I learned from @Lori_M.

This may not be better in practice; it may be just as hard to deal with APPENDV(arr1)(arr2)(arr3)(arr4)...(arrX)(\) as with APPENDXV(arr1,arr2,arr3,...,arrX). But I think its an interesting concept!

APPENDV
Excel Formula:
=LAMBDA(a,
     LAMBDA(b,
         IF(
             TYPE(b)=16,a,
             LET(
                 ra,ROWS(a),
                 rb,ROWS(b),
                 s,SEQUENCE(ra+rb),
                 sca,SEQUENCE(,COLUMNS(a)),
                 scb,SEQUENCE(,COLUMNS(b)),
                 combined,IF(s<=ra,INDEX(a,s,sca),INDEX(b,s-ra,scb)),
                 APPENDV(combined)
             )
         )
     )
 )

APPENDH
Excel Formula:
=LAMBDA(a,
     LAMBDA(b,
         IF(
             TYPE(b)=16,a,
             LET(
                 ca,COLUMNS(a),
                 cb,COLUMNS(b),
                 s,SEQUENCE(,ca+cb),
                 sra,SEQUENCE(ROWS(a)),
                 srb,SEQUENCE(ROWS(b)),
                 combined,IF(s<=ca,INDEX(a,sra,s),INDEX(b,srb,s-ca)),
                 APPENDH(combined)
             )
         )
     )
 )

LAMBDAS_Xlambda.xlsx
ABCDEFGH
1a1 - 1a1 - 2a2 - 1a2 - 2a4 - 1a4 - 2
2a1 - 3a1 - 4a2 - 3a2 - 4a4 - 3a4 - 4
3a1 - 5a1 - 6a2 - 5a2 - 6a4 - 5a4 - 6
4a1 - 7a1 - 8a2 - 7a2 - 8
5a1 - 9a1 - 10a2 - 9a2 - 10a5 - 1a5 - 2
6a1 - 11a1 - 12a5 - 3a5 - 4
7a1 - 13a1 - 14a3 - 1a3 - 2a5 - 5a5 - 6
8a1 - 15a1 - 16a3 - 3a3 - 4
9a1 - 17a1 - 18a3 - 5a3 - 6a6 - 1a6 - 2
10a1 - 19a1 - 20a3 - 7a3 - 8a6 - 3a6 - 4
11a3 - 9a3 - 10a6 - 5a6 - 6
12a6 - 7a6 - 8
13
14=APPENDH(A1#)(B1#)(\)=APPENDV(D1#)(D7#)(\)=APPENDV(G1#)(G5#)(G9#)(\)
15a1 - 1a1 - 2a2 - 1a2 - 2a4 - 1a4 - 2
16a1 - 3a1 - 4a2 - 3a2 - 4a4 - 3a4 - 4
17a1 - 5a1 - 6a2 - 5a2 - 6a4 - 5a4 - 6
18a1 - 7a1 - 8a2 - 7a2 - 8a5 - 1a5 - 2
19a1 - 9a1 - 10a2 - 9a2 - 10a5 - 3a5 - 4
20a1 - 11a1 - 12a3 - 1a3 - 2a5 - 5a5 - 6
21a1 - 13a1 - 14a3 - 3a3 - 4a6 - 1a6 - 2
22a1 - 15a1 - 16a3 - 5a3 - 6a6 - 3a6 - 4
23a1 - 17a1 - 18a3 - 7a3 - 8a6 - 5a6 - 6
24a1 - 19a1 - 20a3 - 9a3 - 10a6 - 7a6 - 8
25
26=APPENDH(A15#)(D15#)(G15#)(\)
27a1 - 1a1 - 2a2 - 1a2 - 2a4 - 1a4 - 2
28a1 - 3a1 - 4a2 - 3a2 - 4a4 - 3a4 - 4
29a1 - 5a1 - 6a2 - 5a2 - 6a4 - 5a4 - 6
30a1 - 7a1 - 8a2 - 7a2 - 8a5 - 1a5 - 2
31a1 - 9a1 - 10a2 - 9a2 - 10a5 - 3a5 - 4
32a1 - 11a1 - 12a3 - 1a3 - 2a5 - 5a5 - 6
33a1 - 13a1 - 14a3 - 3a3 - 4a6 - 1a6 - 2
34a1 - 15a1 - 16a3 - 5a3 - 6a6 - 3a6 - 4
35a1 - 17a1 - 18a3 - 7a3 - 8a6 - 5a6 - 6
36a1 - 19a1 - 20a3 - 9a3 - 10a6 - 7a6 - 8
APPENDH_APPENDV
Cell Formulas
RangeFormula
A1:A10A1="a1 - "&SEQUENCE(10,1,1,2)
B1:B10B1="a1 - "&SEQUENCE(10,1,2,2)
D1:E5D1="a2 - "&SEQUENCE(5,2)
G1:H3G1="a4 - "&SEQUENCE(3,2)
G5:H7G5="a5 - "&SEQUENCE(3,2)
D7:E11D7="a3 - "&SEQUENCE(5,2)
G9:H12G9="a6 - "&SEQUENCE(4,2)
A14,A26,G14,D14A14=FORMULATEXT(A15)
A15:B24A15=APPENDH(A1#)(B1#)(\)
D15:E24D15=APPENDV(D1#)(D7#)(\)
G15:H24G15=APPENDV(G1#)(G5#)(G9#)(\)
A27:F36A27=APPENDH(A15#)(D15#)(G15#)(\)
Dynamic array formulas.
 
Hi, cool trick!! Thanks for sharing!
? i is the most important argument in the formula. when is ignored acts like appending when it has value acts like replacing. I use it a lot in complex single cell formulas. Adds headers , replacing sections of arrays, constructing unusual patterns with ease, and so on. But for bulk appending arrays as they are your trick is super cool. ✌✌?
 
Hi, cool trick!! Thanks for sharing!
? i is the most important argument in the formula. when is ignored acts like appending when it has value acts like replacing. I use it a lot in complex single cell formulas. Adds headers , replacing sections of arrays, constructing unusual patterns with ease, and so on. But for bulk appending arrays as they are your trick is super cool. ✌✌?
You're output has been quite prolific, glad I can contribute back a little! I think could probably update to re-include i parameter, but it was late and I was sleepy! :) Perhaps I try again later!
 
Definitely can be done easily, but I think will be carried for the whole bunch.
Also , apart from the versatility of flexible i I can change directions in the same formula fh(fv(fh(a1,a2,2),a3,3),a4,2).
(a1)(a2)(a3)(a4) ..(\) has like 4 in a line, mine has 3 concentric ( ( ( ) ) ) . indeed I have to write little bit more, versatility has to come with some cost?
We have to create one looking like this (a1,v,2)(a2,h,3)(a3,v,2) ,and with recursion, and only 3 rows long formula.?.
Regarding being prolific, I am not prolific at all. Manny ideas and no time. Started a while ago, a study for kind of 3D arrays with recursion or polinomial goal seek solving , still in pending .? Can not alocate to much time to this , only part of my former outdoor spare time. But I am very happy that I found this forum. Actually Mike Girvin pointed it out to me, and here I am. See you around.✌✌??
 

Forum statistics

Threads
1,214,922
Messages
6,122,281
Members
449,075
Latest member
staticfluids

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