AINDEXERL

AINDEXERL(Array,[Column_Numbers],[By_Col])
Array
Required. Range to return row or column numbers.
[Column_Numbers]
Optional. 1☛ return column numbers; 0 or ignored☛ return row numbers.
[By_Col]
Optional. 1☛ stack column by column; 0 or ignored☛ stack row by row.

AINDEXERL returns a stack of all relative row numbers for each column or all relative column numbers for each row in an array. Uses MAKEARRAY!

schardt679

Board Regular
Joined
Mar 27, 2021
Messages
58
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
  3. Web
AINDEXERL returns a stack of all relative row numbers for each column or all relative column numbers for each row in an array. Uses MAKEARRAY!

Thanks to Rico S's LISTCOLUMNS & LISTROWS for the inspiration (from Mr. Excel's UNIQUE of Rectangular Range Using MAKEARRAY in Excel - 2416).
ARRAYSIZE(array) =LAMBDA(array, ROWS(array)*COLUMNS(array)).
LISTCOLUMNS(array) =LAMBDA(array, LET(colCount, COLUMNS(array), modArray, MOD(SEQUENCE(ARRAYSIZE(array)), colCount), columnNumbers, IF(modArray=0, colCount, modArray), columnNumbers) ).
LISTROWS(array) =LAMBDA(array, ROUNDUP(SEQUENCE(ARRAYSIZE(array))/COLUMNS(array), 0)).
Calls CELLCOUNT.
Other functions on minisheet: AFORMULATEXT.

Screen Tip/ Comment: =AINDEXERL(Array☛ range to return row/column numbers, [Column_Numbers]☛ 1=return column numbers; 0/❎=return row numbers✅, [By_Col]☛ 1=stack column by column; 0/❎=row by row✅) ⁂[]=optional; ✅=default; ❎=omit

Excel Formula:
=LAMBDA(Array,[Column_Numbers],[By_Col],
      LET(Arr, Array,          nCol?, Column_Numbers,          Col?, By_Col,
             NumScan, AND(nCol?<>{1,0}),          NumMSG, "Column_Numbers=1,0",
             ColScan, AND(Col?<>{1,0}),          ColMSG, "By_Col=1,0",
             ERRORS, IFS(NumScan, NumMSG,  ColScan,  ColMSG,  1, 0),
             RowCt, CELLCOUNT(Arr, 1),          ColCt, CELLCOUNT(Arr, 2),          TotCt, CELLCOUNT(Arr),
             RowSel, MAKEARRAY(TotCt,, LAMBDA(R,C,   IF(Col?, MOD(R-1, RowCt)+1,  R/ColCt))),
             ColSel, MAKEARRAY(TotCt,, LAMBDA(R,C,   IF(Col?, R/RowCt,  MOD(R-1, ColCt)+1))),
             Result, ROUNDUP(IF(nCol?=1, ColSel,  RowSel),),          Return, IF(ERRORS<>0, ERRORS,  Result),
             Return
       )
  )
LAMBDA Examples.xlsx
ABCDEFGHI
1AINDEXERL
2
3Original DataColumn_Numbers:Result
41#VALUE!By_Col:1
521
6342
72
8Row numbers are returned3
9Formula in cell H4☛ =AINDEXERL(B4:C6, F3, F4)3
10
11
12
13Original DataColumn_Numbers:0Result
141#VALUE!By_Col:11
1522
16343
171
18Column numbers are returned2
19Formula in cell H14☛ =AINDEXERL(B14:C16, F13, F14)3
20
21
22
23Original DataColumn_Numbers:1Result
241#VALUE!By_Col:01
2522
26341
272
28Column numbers are returned1
29Formula in cell H24☛ =AINDEXERL(B24:C26, F23, F24)2
30
31
32
33Original DataColumn_Numbers:1Result
341#VALUE!By_Col:11
3521
36341
372
38Column numbers are returned2
39Formula in cell H34☛ =AINDEXERL(B34:C36, F33, F34)2
40
AINDEXERL
Cell Formulas
RangeFormula
H4:H9,H34:H39,H24:H29,H14:H19H4=AINDEXERL(B4:C6, F3, F4)
B9,B39,B29,B19B9=AFORMULATEXT(H4)
Dynamic array formulas.
 
Upvote 0
This returns #Valueerror. Did something change?
 
I traced it back to the updated CellCount, which calls Avalue, and the formula for AINDEXERL updates to:
Excel Formula:
=LAMBDA(Array,[Column_Numbers],[By_Col],
      LET(Arr, Array,          nCol?, Column_Numbers,          Col?, By_Col,
             NumScan, AND(nCol?<>{1,0}),          NumMSG, "Column_Numbers=1,0",
             ColScan, AND(Col?<>{1,0}),          ColMSG, "By_Col=1,0",
             ERRORS, IFS(NumScan, NumMSG,  ColScan,  ColMSG,  1, 0),
             RowCt, CELLCOUNT(Arr, 1),          ColCt, CELLCOUNT(Arr, 2),          TotCt, CELLCOUNT(Arr, 0),
             RowSel, MAKEARRAY(TotCt,, LAMBDA(R,C,   IF(Col?, MOD(R-1, RowCt)+1,  R/ColCt))),
             ColSel, MAKEARRAY(TotCt,, LAMBDA(R,C,   IF(Col?, R/RowCt,  MOD(R-1, ColCt)+1))),
             Result, ROUNDUP(IF(nCol?=1, ColSel,  RowSel),),          Return, IF(ERRORS<>0, ERRORS,  Result),
             Return
       )
  )
 

Forum statistics

Threads
1,214,431
Messages
6,119,462
Members
448,899
Latest member
maplemeadows

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