How to Wrap 2D Arrays in Excel Using Custom LAMBDA Functions
Question details
The user needs to reshape two-dimensional arrays into row or column blocks using custom LAMBDA functions, optimizing performance by avoiding the initial flattening of the source array.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Reshaping large 2D arrays into specific row or column blocks while managing padding for incomplete blocks and comparing calculation performance.
- Observed behavior
- The goal is to implement and utilize WrapCols2D or WrapRows2D functions to create blocks, pad incomplete blocks correctly, and achieve better performance compared to traditional TOROW/TOCOL methods.
Ensure you are using a version of Excel that supports Dynamic Arrays and the LAMBDA function, such as Microsoft 365 or Excel 2021.
Implement Custom WrapCols2D and WrapRows2D LAMBDA Functions
Define custom LAMBDA functions in the Name Manager to reshape 2D arrays directly into row or column blocks without flattening.
Using custom LAMBDAs allows you to bypass the intermediate step of flattening a 2D array with TOROW or TOCOL. This direct 2D-to-2D transformation can significantly improve performance and memory usage on very large datasets by avoiding Excel's single-column or single-row limits.
Navigate to the Formulas tab on the Excel ribbon and click on 'Name Manager'.
Click 'New', enter the name 'WrapRows2D', and input your custom LAMBDA formula logic designed to extract row blocks using functions like INDEX or MAKEARRAY.
Create another new name called 'WrapCols2D' and input the corresponding LAMBDA formula for creating column blocks.
In your worksheet, type `=WrapRows2D(A1:D10, 3, "N/A")` to reshape the array A1:D10 into blocks of 3 rows, where the third argument specifies the padding value.

Use Built-in WRAPROWS and WRAPCOLS with TOROW or TOCOL
Combine built-in dynamic array functions to achieve a similar wrapping result without writing custom LAMBDA formulas.
Handle Dynamic Arrays Efficiently with WPS Spreadsheet
WPS Spreadsheet fully supports modern dynamic array functions, allowing you to seamlessly reshape, filter, and analyze large datasets without complex workarounds.
- 1. Open WPS Spreadsheet: Launch WPS Office and open the workbook containing the 2D arrays you want to reshape.
- 2. Enter Dynamic Array Formulas: Select an empty cell and type your array formula, such as `=WRAPROWS(TOROW(A1:D10), 5)`.
- 3. Press Enter to Spill: Press Enter. WPS Spreadsheet will automatically calculate and spill the reshaped array into the adjacent cells, efficiently handling the dynamic output.

Frequently Asked Questions
Why should I use a custom LAMBDA instead of WRAPROWS and TOROW?
A custom LAMBDA like WrapRows2D avoids flattening the 2D array into a 1D array first. This can save memory, prevent hitting the 1,048,576 row limit in a temporary array, and improve calculation speed when dealing with massively large datasets.
How do I pad incomplete blocks in a reshaped dynamic array?
Both the built-in WRAPROWS function and custom wrapping LAMBDAs accept a 'pad_with' argument. You can input a text string like "Missing" or use the NA() function to fill empty spaces in the final block.
What happens if my flattened array exceeds Excel's limits?
If you use TOROW or TOCOL on a massive 2D array and the resulting 1D array exceeds Excel's row or column limits, the formula will return a #CALC! error. Using direct 2D-to-2D block wrapping techniques helps avoid this limitation.




