MREPEAT

MREPEAT(reference,[counts],[stack])
reference
Required. Specifies the function input and can be any 1D array/range.
counts
Optional. Specifies the count(s) of the element(s) in "reference" and can be either omitted or any integer(s).
stack
Optional. Specifies the output format of the function and takes two general arguments: 0 or omitted or FALSE, for linear output; or, 1 or TRUE or any number other than 0, for stacked output.

MREPEAT is a powerful repeating solution that spills array elements of any data type at the specified number of counts with the ability to insert blanks and filter out specific elements as well as stacking

Rnkhch

Well-known Member
Joined
Apr 28, 2018
Messages
578
Office Version
  1. 365
Platform
  1. Windows
MREPEAT is a powerful repeating solution that spills array elements of any data type at the specified number of counts with the ability to insert blanks and filter out specific elements as well as stacking


MREPEAT takes three parameters, one required and two optional, as follows:
A) The first parameter, required, specifies the function input and can be any 1D array/range

Note that any data type, even errors, can be included as reference (for a full list of all data types, refer to the latest update of XTYPE)

Note that the elements entered in this parameter can be only one-dimensional arrays; entering two-dimensional arrays will cause the function to return a #VALUE! error

Note that entering elements in column format (i.e. separated with semicolons) (e.g. {3;"book";FALSE} will result in an output which is horizontal; however, this output is NOT equivalent to the transposed version of row format (i.e. counts separated with commas) as the function practically linearizes the output by scanning vertically down the stacked version of the output (see section C below) whether the counts are entered in row or column format. I intentionally coded the output this way as an extra feature for more diverse output options. If stack is turned on, however, the two outputs will be the transposed version of each other

B) The second parameter, optional, specifies the count(s) of the element(s) in "reference" and can be either omitted or any integer(s)

Note that if more than one number needs to be entered, they should be included in array brackets "{}" per native syntax

Note that there is a one-to-one correspondence between the numbers in "counts" and the elements of the "reference"

Note that if this parameter is left omitted, the default count of 1 will be applied to all elements of the reference

Note that if fewer numbers than the count of the reference elements are entered, only those elements of the reference that have corresponding numbers in "counts" will be repeated and the remaining reference elements will be ignored; thus, if additional numbers are later added to "counts", the reference elements corresponding to these new numbers will start to appear in the output spill

Note that if more numbers than the count of the reference elements are entered, the numbers past the last point of correspondence to the reference elements will be ignored; thus, if more elements are later added to the reference, these new elements will be repeated in the output spill as long as they are in correspondence to a number in "counts"

Note that if zero is used for any "reference" element, that element will be omitted from the output spill and not repeated

Note that non-integer values will be rounded down to the nearest integer

Note that if only zero(s) or number(s) between 0 and 1 are included in this parameter, the output will be a #CALC! error

Note that including negative number(s) in this parameter will result in sequence(s) of blanks with count(s) corresponding to the absolute value(s) of the negative number(s); thus, if only one or more negative numbers are included, the output will be a series of blanks

Note that the function linearizes the numbers in this parameter, so they can technically be entered either in row format (i.e. separated with commas) or column format (i.e. separated with semicolons)

Note that if anything other than numbers is entered in this parameter, the function will crash to an #N/A

C) The third parameter, optional, specifies the output format of the function and takes two general arguments:
0 or omitted or FALSE, for linear output
1 or TRUE or any number other than 0, for stacked output

Note that besides being omitted, only one real number or TRUE/FALSE can be entered in this parameter; entering more than one number or logical will cause the function to crash to an #N/A

Note that if anything other than the specified allowed arguments is entered, the function will crash to an #N/A


(You can download my template from the link in my signature below, which makes it easier to obtain/test the functions compared to manually pasting from the text/XL2BB)

MREPEAT
Excel Formula:
=LAMBDA(reference,[counts],[stack],
   LET(
      aa,IFERROR(COLUMNS(reference),1),
      ac,IFERROR(ROWS(reference),1),
      ag,TOROW(IF(IO(counts),SEQUENCE(,MAX(aa,ac),,0),counts)),
      ae,aa>=ac,
      af,COLUMNS(ag),
      ab,IF(ae,af,1),
      ad,IF(ae,1,af),
      v,IF(
         ab<aa,
         HSTACK(counts,SEQUENCE(1,aa-ab,0,0)),
         IF(
            ad<ac,
            VSTACK(TOCOL(counts),SEQUENCE(ac-ad,1,0,0)),
            IF(ae,ag,TRANSPOSE(ag))
         )
      ),
      n,IF(
         ab>aa,
         CHOOSECOLS(v,SEQUENCE(,aa)),
         IF(ad>ac,CHOOSEROWS(v,SEQUENCE(ac)),v)
      ),
      z,IF(reference="","",reference),
      a,IF(n<0,"",IF(AND(aa=1,ac=1),CHOOSECOLS(z,1),z)),
      s,IF(IO(stack),0,IF(AND(ROWS(IFERROR(stack,1))=1,COLUMNS(IFERROR(stack,1))=1),INDEX(stack,1),NA())),
      m,ROWS(n),
      l,COLUMNS(n),
      o,IF(l>=m,1,2),
      r,SWITCH(o,1,SEQUENCE(MAX(ABS(n))),SEQUENCE(,MAX(ABS(n)))),
      c,SWITCH(o,1,SEQUENCE(,l),SEQUENCE(m)),x,r<=ABS(INDEX(n,c)),
      k,ROWS(a),h,COLUMNS(a),b,IF(h>1,1,IF(k=1,1,0)),
      d,IF(b,h,k),
      p,FILTER(IF(b,SEQUENCE(,h),SEQUENCE(k)),n<>0),
      q,IF(x,INDEX(a,c),""),
      y,IF(b,CHOOSECOLS(q,p),CHOOSEROWS(q,p)),
      u,IF(b,CHOOSECOLS(x,p),CHOOSEROWS(x,p)),
      f,COLUMNS(y),
      e,ROWS(y),
      g,SEQUENCE(e*f),
      i,MOD(g-1,e)+1,
      j,INT((g-1)/e)+1,
      t,FILTER(INDEX(y,i,j),INDEX(u,i,j)),
      w,IF(s,y,SWITCH(o,1,t,TRANSPOSE(t))),
      IF(
         AND(
            OR(ISNUMBER(s),ISLOGICAL(s)),
            ISNUMBERS(counts,TRUE)
         ),
         w,
         NA()
      )
   )
)

ISNUMBERS (Returns TRUE if ALL elements in the reference are numbers and FALSE otherwise)
Excel Formula:
=LAMBDA(reference,[if_omitted],
   IF(
      IO(reference),
      IF(IO(if_omitted),FALSE,if_omitted),
      IF(PRODUCT(ISNUMBER(reference)*1),TRUE,FALSE)
   )
)

IO (shortened form of ISOMITTED)
Excel Formula:
=LAMBDA(parameter,
   ISOMITTED(parameter)
)


MREPEAT.xlsx
ABCDEFGHIJKLMNOPQRSTUV
1
2#CALC!
3
434book TRUEFALSE#DIV/0!
5
634book TRUEFALSE#DIV/0!
7
834book TRUEFALSE#DIV/0!
9
1034book TRUEFALSE#DIV/0!
11
124545454545note#REF!TRUE4545
13note45454545note#REF!TRUE4545
14#REF!45454545#REF!TRUE4545
15TRUEnotenotenote#REF!TRUEnotenote
16notenotenoteTRUEnotenote
17#REF!TRUE#REF!#REF!
18#REF!TRUE45noteTRUE#REF!#REF!
19#REF!TRUE45noteTRUE#REF!#REF!
20#REF!TRUE45TRUE#REF!#REF!
21TRUETRUETRUETRUETRUE
22TRUETRUETRUETRUE
23TRUETRUETRUE
24TRUETRUE45noteTRUETRUE
25TRUETRUE45noteTRUETRUE
2645TRUE
27TRUE
28TRUE
29
3045note#REF!TRUE45note#REF!TRUE45#REF!TRUE#REF!TRUETRUE
31
32
33bookFALSE#DIV/0!0TRUEbook
34book
35bookFALSE#DIV/0!0TRUEbookFALSE#DIV/0!0TRUEbookFALSE#DIV/0!TRUEFALSE#DIV/0!FALSEbook
36FALSE
37bookFALSE0TRUEbookFALSE0TRUEbookFALSETRUEFALSEFALSEFALSE
38FALSE
39bookFALSE0TRUEbookFALSE0TRUEbookFALSETRUEFALSEFALSEFALSE
40FALSE
41bookbookbookbookbookbookbookbookbook#DIV/0!
42FALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSEFALSE#DIV/0!
43#DIV/0!#DIV/0!#DIV/0!#DIV/0!00#DIV/0!
440000TRUETRUETRUE#DIV/0!
45TRUETRUETRUETRUETRUETRUE0
460
47bookFALSE#DIV/0!0TRUEbookFALSE#DIV/0!0TRUEbookFALSE#DIV/0!TRUEFALSE#DIV/0!FALSETRUE
48TRUE
49bookFALSE#DIV/0!0bookFALSE#DIV/0!0bookFALSE#DIV/0!FALSE#DIV/0!FALSETRUE
50
51
52data type12313233344142162164
53numbertextblank_realblank_formulablank_spaceblank_pastedlogicallogicalerrorerror
5427book  TRUEFALSE#DIV/0!#REF!
5527book    TRUEFALSE#DIV/0!#REF!
5627book TRUEFALSE#DIV/0!#REF!
57
58
5927book TRUEFALSE#DIV/0!#REF!27book TRUEFALSE#DIV/0!#REF!
60
6127272727book TRUEFALSE#DIV/0!#REF!
62bookbook2727book TRUEFALSE#DIV/0!#REF!
63book
64book
65
66#VALUE!  
67TRUETRUE
68FALSEFALSE
69#DIV/0!#DIV/0!
70#REF!#REF!
71
72
73TRUE
74TRUE
75FALSE
76FALSE
77#DIV/0!
78#DIV/0!
79#REF!
80#REF!
81
MREPEAT
Cell Formulas
RangeFormula
B2B2=LAMBDA(reference,[counts],[stack],LET(aa,IFERROR(COLUMNS(reference),1),ac,IFERROR(ROWS(reference),1),ag,TOROW(IF(IO(counts),SEQUENCE(,MAX(aa,ac),,0),counts)),ae,aa>=ac,af,COLUMNS(ag),ab,IF(ae,af,1),ad,IF(ae,1,af),v,IF(ab<aa,HSTACK(counts,SEQUENCE(1,aa-ab,0,0)),IF(ad<ac,VSTACK(TOCOL(counts),SEQUENCE(ac-ad,1,0,0)),IF(ae,ag,TRANSPOSE(ag)))),n,IF(ab>aa,CHOOSECOLS(v,SEQUENCE(,aa)),IF(ad>ac,CHOOSEROWS(v,SEQUENCE(ac)),v)),z,IF(reference="","",reference),a,IF(n<0,"",IF(AND(aa=1,ac=1),CHOOSECOLS(z,1),z)),s,IF(IO(stack),0,IF(AND(ROWS(IFERROR(stack,1))=1,COLUMNS(IFERROR(stack,1))=1),INDEX(stack,1),NA())),m,ROWS(n),l,COLUMNS(n),o,IF(l>=m,1,2),r,SWITCH(o,1,SEQUENCE(MAX(ABS(n))),SEQUENCE(,MAX(ABS(n)))),c,SWITCH(o,1,SEQUENCE(,l),SEQUENCE(m)),x,r<=ABS(INDEX(n,c)),k,ROWS(a),h,COLUMNS(a),b,IF(h>1,1,IF(k=1,1,0)),d,IF(b,h,k),p,FILTER(IF(b,SEQUENCE(,h),SEQUENCE(k)),n<>0),q,IF(x,INDEX(a,c),""),y,IF(b,CHOOSECOLS(q,p),CHOOSEROWS(q,p)),u,IF(b,CHOOSECOLS(x,p),CHOOSEROWS(x,p)),f,COLUMNS(y),e,ROWS(y),g,SEQUENCE(e*f),i,MOD(g-1,e)+1,j,INT((g-1)/e)+1,t,FILTER(INDEX(y,i,j),INDEX(u,i,j)),w,IF(s,y,SWITCH(o,1,t,TRANSPOSE(t))),IF(AND(OR(ISNUMBER(s),ISLOGICAL(s)),ISNUMBERS(counts,TRUE)),w,NA())))
B4B4=MREPEAT(34)
D4D4=MREPEAT("book")
F4F4=MREPEAT("")
H4H4=MREPEAT(TRUE)
J4J4=MREPEAT(FALSE)
L4L4=MREPEAT(#DIV/0!)
B6B6=MREPEAT(34,1)
D6D6=MREPEAT("book",1)
F6F6=MREPEAT("",1)
H6H6=MREPEAT(TRUE,1)
J6J6=MREPEAT(FALSE,1)
L6L6=MREPEAT(#DIV/0!,1)
B8B8=MREPEAT(34,{1})
D8D8=MREPEAT("book",{1})
F8F8=MREPEAT("",{1})
H8H8=MREPEAT(TRUE,{1})
J8J8=MREPEAT(FALSE,{1})
L8L8=MREPEAT(#DIV/0!,{1})
B10B10=MREPEAT({34},{1})
D10D10=MREPEAT({"book"},{1})
F10F10=MREPEAT({""},{1})
H10H10=MREPEAT({TRUE},{1})
J10J10=MREPEAT({FALSE},{1})
L10L10=MREPEAT({#DIV/0!},{1})
B12:B15B12=MREPEAT({45,"note",#REF!,TRUE})
D12:D25D12=MREPEAT({45,"note",#REF!,TRUE},{3,2,4,5})
F12:F25F12=MREPEAT({45,"note",#REF!,TRUE},{3,2,-4,5})
H12:H21H12=MREPEAT({45,"note",#REF!,TRUE},{3,2,0,5})
J12:M16J12=MREPEAT({45,"note",#REF!,TRUE},{3,2,4,5},1)
O12:O25O12=MREPEAT({45,"note",#REF!,TRUE},{3,2,4,5,6})
Q12:Q20Q12=MREPEAT({45,"note",#REF!,TRUE},{3,2,4})
J18:M22J18=MREPEAT({45,"note",#REF!,TRUE},{3,2,-4,5},1)
J24:L28J24=MREPEAT({45,"note",#REF!,TRUE},{3,2,0,5},1)
B30:O30B30=MREPEAT({45;"note";#REF!;TRUE},{3,2,4,5})
B33:F33B33=MREPEAT({"book";FALSE;#DIV/0!;0;TRUE})
T33:T49T33=MREPEAT({"book",FALSE,#DIV/0!,0,TRUE},{3,5,4,2,3})
B35:R35B35=MREPEAT({"book";FALSE;#DIV/0!;0;TRUE},{3,5,4,2,3})
B37:R37B37=MREPEAT({"book";FALSE;#DIV/0!;0;TRUE},{3,5,-4,2,3})
B39:N39B39=MREPEAT({"book";FALSE;#DIV/0!;0;TRUE},{3,5,0,2,3})
B41:F45B41=MREPEAT({"book";FALSE;#DIV/0!;0;TRUE},{3,5,4,2,3},1)
H41:L45H41=MREPEAT({"book";FALSE;#DIV/0!;0;TRUE},{3,5,-4,2,3},1)
N41:R44N41=MREPEAT({"book";FALSE;#DIV/0!;0;TRUE},{3,5,0,2,3},1)
B47:R47B47=MREPEAT({"book";FALSE;#DIV/0!;0;TRUE},{3,5,4,2,3,4})
B49:O49B49=MREPEAT({"book";FALSE;#DIV/0!;0;TRUE},{3,5,4,2})
E54E54=IF(1,"")
J54J54=1/0
B55:K56B55=MREPEAT(B54,2)
B59:U59B59=MREPEAT(TRANSPOSE(B54:K54),{2,2,2,2,2,2,2,2,2,2})
B61:C70B61=MREPEAT(TRANSPOSE(B54:K54),{2,2,2,2,2,2,2,2,2,2},1)
E61:E80E61=MREPEAT(B54:K54,{2,2,2,2,2,2,2,2,2,2})
G61:P62G61=MREPEAT(B54:K54,{2,2,2,2,2,2,2,2,2,2},1)
L66L66=MREPEAT()
N66N66=MREPEAT(,)
P66:P68P66=MREPEAT(,3)
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,157
Members
453,021
Latest member
Justyna P

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