Skip to content

Instantly share code, notes, and snippets.

@YeeBePrime
Created September 19, 2022 08:02
Show Gist options
  • Save YeeBePrime/4da8288a8fb2b7d19943a3be8d3487f9 to your computer and use it in GitHub Desktop.
Save YeeBePrime/4da8288a8fb2b7d19943a3be8d3487f9 to your computer and use it in GitHub Desktop.
Remove blank cells in array and shift cells in that row to the left using Excel lambda function
/*
removeBlankShiftLeft
Description
Remove blank cells in array and shift cells in that row to the left.
Syntax
removeBlankShiftLeft (datarange, [lastresult], [lastrow])
The removeBlankShiftLeft function syntax has the following arguments:
datarange Required. can be 2D array
lastresult Optional. For recursive purpose only.
lastrow Optional. For recursive purpose only.
Example
A1:C3 A B C
D E
F G H
=removeBlankShiftLeft(A1:C3)
Return
A B C
D E
F G H
*/
removeBlankShiftLeft=LAMBDA(datarange, [lastresult], [lastrow],
LET(
rng, datarange,
_lresult, IF(
ISOMITTED(
lastresult
),
"",
lastresult
),
_lrow, lastrow,
_nrow, IF(
_lrow > 0,
_lrow + 1,
1
),
_rngRow, CHOOSEROWS(
rng,
_nrow
),
result, IFERROR(
VSTACK(
_lresult,
TRIM(
FILTER(
_rngRow,
_rngRow <>
""
)
)
),
""
),
IF(
_nrow + 1 <=
ROWS(rng),
removeBlankShiftLeft(
rng,
result,
_nrow
),
DROP(result, 1)
)
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment