Skip to content

Instantly share code, notes, and snippets.

@SergeiStPete
Last active June 15, 2023 10:03
Show Gist options
  • Save SergeiStPete/69e52f3b2a53b038aa3d69b64412437e to your computer and use it in GitHub Desktop.
Save SergeiStPete/69e52f3b2a53b038aa3d69b64412437e to your computer and use it in GitHub Desktop.
Excel, Lambda - FillDown / FillUp vertical range
/* FillUp/FillDown column range functions
Sergei Baklan
Updated 2022-03-05
-------------------------------------------------------*/
/*
FUNCTION NAME: IFBLANK
based on Chris Gross function
https://gist.github.com/chgrossMSFT/d172fd552cf6893bcdc7942223cb0e55
DESCRIPTION: Checks if a value is blank and returns value_if_blank if it is
ARGS:
value: The value to check if it's blank
[value_if_blank]: The value to return if a blank value is found.
If ommitted blank empty string is returned.
EXAMPLE:
=IFBLANK(,"blankVal")
*/
IFBLANK =LAMBDA(value, [value_if_blank],
IF(
ISBLANK(value),
IF(ISOMITTED(value_if_blank), "", value_if_blank),
value
)
);
/*
FUNCTION NAME: FillDown
DESCRIPTION: Returns a spill where the value of a previous cell
is propagated to the blank cells below.
ARGS:
array: Array or range to fill down
dummy: Optional parameter for internal purposes, shall not be used
EXAMPLE:
=FillDown(A1:A10)
*/
FillDown = LAMBDA(array, [dummy],
LET(
n, IFBLANK(dummy, ROWS(array)),
IF(
n = 1,
IFBLANK( INDEX(array, 1) ),
LET(
a, FillDown(array, n - 1),
IF(
SEQUENCE(n) < n,
a,
IFBLANK( INDEX(array, n),
IFBLANK(INDEX(a, n - 1))
)
)
)
)
)
);
/*
FUNCTION NAME: reverseColumnRange
DESCRIPTION: Reverses range in column. To use in other functions,
if return to range blanks are returned as zeroes
ARGS:
array: Array or range to reverse
EXAMPLE:
=reverseColumnRange(A1:A10)
*/
reverseColumnRange = LAMBDA(range,
LET(
rowsInRange, ROWS(range),
INDEX(range, SEQUENCE(rowsInRange, , rowsInRange, -1))
)
);
/*
FUNCTION NAME: FillUp
DESCRIPTION: Returns a spill where the value of the next cell
is propagated to the blank cells above.
ARGS:
array: Array or range to fill down
dummy: Optional parameter for internal purposes, shall not be used
EXAMPLE:
=FillUp(A1:A10)
*/
FillUp = LAMBDA(range,
reverseColumnRange( FillDown(reverseColumnRange(range))));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment