Skip to content

Instantly share code, notes, and snippets.

@SergeiStPete
Last active June 15, 2023 10:03
Show Gist options
  • Save SergeiStPete/513e5b85ff6280d2362eceee6c9be6a7 to your computer and use it in GitHub Desktop.
Save SergeiStPete/513e5b85ff6280d2362eceee6c9be6a7 to your computer and use it in GitHub Desktop.
Insert blank rows
// variants to https://gist.github.com/havishmad/0f8e5f785146633f0f8533b5820dd0fe
insertBlankRows=
LAMBDA( data,
LET(
columnsInRange, COLUMNS(data),
emptyRow, IF( SEQUENCE(, columnsInRange ), ""),
rowsInRange, ROWS( data ),
addEmptyRow, VSTACK( TAKE( data, 1), emptyRow),
IF( rowsInRange = 1,
data,
VSTACK( addEmptyRow,
insertBlankRows( DROP( data, 1) ) )
)
) );
////
insertBlankRowsShortened=
LAMBDA( data,
LET(
emptyRow, IF( SEQUENCE(, COLUMNS(data) ), ""),
addEmptyRow, VSTACK( TAKE( data, 1), emptyRow),
IF( ROWS( data ) = 1,
data,
VSTACK( addEmptyRow,
insertBlankRows( DROP( data, 1) ) )
)
) );
/// one more variant
emptyRow=
LAMBDA( numberOfColumns,
IF( SEQUENCE(, numberOfColumns ), "")
);
groupIndex=
LAMBDA( number, groupSize,
INT( (number-1)/groupSize) + 1 );
insertBlankRowsReduce=
LAMBDA( data,
REDUCE(
"",
SEQUENCE( 2 * ROWS(data) ),
LAMBDA( a, v,
IF( v = SEQUENCE(v),
IF( ISODD(v),
CHOOSEROWS( data, groupIndex(v, 2) ),
emptyRow( COLUMNS(data)) ),
a
))
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment