Skip to content

Instantly share code, notes, and snippets.

@ncalm
Created November 28, 2022 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ncalm/1ea63fc430d3547b1ee8429e7f186b74 to your computer and use it in GitHub Desktop.
Save ncalm/1ea63fc430d3547b1ee8429e7f186b74 to your computer and use it in GitHub Desktop.
This Excel Lambda function provides a simplified interface for creating lists of integers
/*
from is the first integer in the list
to is the target integer in the list
step is the difference between successive integers
*/
L =LAMBDA(from,to,[step],
LET(
_step, IF(ISOMITTED(step), IF(from > to, -1, 1), step),
//arguments should be single integers
_check, LAMBDA(x, OR(ROWS(x) + COLUMNS(x) <> 2, INT(x) <> x)),
IF(
//if any of these are TRUE, then there's an array somewhere
//array = no bueno
OR(_check(from), _check(to), _check(_step)),
#VALUE!,
LET(
_diff, MAX(from, to) - MIN(from, to),
_rows, ROUNDUP((_diff + 1) / ABS(_step), 0),
SEQUENCE( _rows, 1, from, _step)
)
)
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment