Created
August 17, 2025 19:30
-
-
Save gahrae/27205d9ef9f2c048ff9de5dcf11e8dfa to your computer and use it in GitHub Desktop.
Excel lambda function to get array data (default is top-down, but can get left-to-right, or both, e.g. 2D array).
This file contains hidden or 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
| =LAMBDA(cell, [seek_down], [seek_right], | |
| LET( | |
| MAX_COLS, 16384, | |
| MAX_ROWS, 1048576, | |
| sd, IF(ISOMITTED(seek_down), TRUE, seek_down), | |
| sr, IF(ISOMITTED(seek_right), FALSE, seek_right), | |
| start_row, ROW(cell), | |
| start_col, COLUMN(cell), | |
| IF( | |
| ISBLANK(cell), | |
| "", | |
| LET( | |
| right_bound, IF( | |
| sr, | |
| LET( | |
| test_range, OFFSET(cell, 0, 0, 1, MAX_COLS - start_col + 1), | |
| empty_pos, MATCH(TRUE, ISBLANK(test_range), 0), | |
| IF(ISERROR(empty_pos), MAX_COLS, start_col + empty_pos - 2) | |
| ), | |
| start_col | |
| ), | |
| down_bound, IF( | |
| sd, | |
| LET( | |
| test_range, OFFSET(cell, 0, 0, MAX_ROWS - start_row + 1, 1), | |
| empty_pos, MATCH(TRUE, ISBLANK(test_range), 0), | |
| IF(ISERROR(empty_pos), MAX_ROWS, start_row + empty_pos - 2) | |
| ), | |
| start_row | |
| ), | |
| width, right_bound - start_col + 1, | |
| height, down_bound - start_row + 1, | |
| IF( | |
| AND(sr, sd), | |
| MAKEARRAY( | |
| height, | |
| width, | |
| LAMBDA(r, c, | |
| LET( | |
| target_cell, OFFSET(cell, r - 1, c - 1, 1, 1), | |
| IF(ISBLANK(target_cell), "", target_cell) | |
| ) | |
| ) | |
| ), | |
| IF( | |
| sr, | |
| OFFSET(cell, 0, 0, 1, width), | |
| IF(sd, OFFSET(cell, 0, 0, height, 1), cell) | |
| ) | |
| ) | |
| ) | |
| ) | |
| ) | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment