Created
November 28, 2022 22:41
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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