Skip to content

Instantly share code, notes, and snippets.

@ExcelRobot
Last active December 8, 2024 20:25
Show Gist options
  • Save ExcelRobot/4f75861ff3178026424fba8f215a8cba to your computer and use it in GitHub Desktop.
Save ExcelRobot/4f75861ff3178026424fba8f215a8cba to your computer and use it in GitHub Desktop.
Indirect Expand Lambda
/*
Name: Indirect Expand (IndirectExpand)
Description: Converts a range address (and optional sheet name) to a reference to those cells and the cells surrounding them by a user specified distance.
Parameters:
address - range address text
[sheet_name] - name of sheet, if not active sheet
[expand_distance] - number of cells in all directions to expand the selection (default: 0)
Source: @ExcelRobot
*/
IndirectExpand =LAMBDA(address, [sheet_name], [expand_distance], LET(
\\LambdaName, "IndirectExpand",
\\CommandName, "Indirect Expand",
\\Description, "Converts a range address (and optional sheet name) to a reference to those cells and the cells surrounding them by a user specified distance.",
\\Parameters, {
"address","range address text";
"[sheet_name]","name of sheet, if not active sheet";
"[expand_distance]","number of cells in all directions to expand the selection (default: 0)"
},
\\Source, "@ExcelRobot",
_Prefix, IF(
ISOMITTED(sheet_name),
"",
"'" & SUBSTITUTE(sheet_name, "''", "'") & "'!"
),
_Address, _Prefix & address,
_Result, IF(
ISOMITTED(expand_distance),
INDIRECT(_Address),
OFFSET(
INDIRECT(_Address),
-expand_distance,
-expand_distance,
ROWS(INDIRECT(_Address)) + 2 * expand_distance,
COLUMNS(INDIRECT(_Address)) + 2 * expand_distance
)
),
_Result
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment