Function Problems

How to Wrap 2D Arrays in Excel Using Custom LAMBDA Functions

John WilsonJohn Wilson Nov 10, 2026 869 views

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.

How to Wrap 2D Arrays in Excel Using Custom LAMBDA Functions
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.
Before you start

Ensure you are using a version of Excel that supports Dynamic Arrays and the LAMBDA function, such as Microsoft 365 or Excel 2021.

Solution 1Recommended

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.

1
Open Name Manager

Navigate to the Formulas tab on the Excel ribbon and click on 'Name Manager'.

2
Define WrapRows2D

Click 'New', enter the name 'WrapRows2D', and input your custom LAMBDA formula logic designed to extract row blocks using functions like INDEX or MAKEARRAY.

3
Define WrapCols2D

Create another new name called 'WrapCols2D' and input the corresponding LAMBDA formula for creating column blocks.

4
Apply the Function

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.

Implement Custom WrapCols2D and WrapRows2D LAMBDA Functions
Padding Incomplete Blocks: If your custom LAMBDA is configured correctly, incomplete blocks will be cleanly padded with your specified fill value, such as NA() or a custom string.
Powerful Spreadsheet Data Analysis

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. 1. Open WPS Spreadsheet: Launch WPS Office and open the workbook containing the 2D arrays you want to reshape.
  2. 2. Enter Dynamic Array Formulas: Select an empty cell and type your array formula, such as `=WRAPROWS(TOROW(A1:D10), 5)`.
  3. 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.
Full compatibility with Microsoft Excel dynamic array functions like WRAPROWS, WRAPCOLS, and TOCOL.High performance and calculation stability when processing large 2D arrays.Free, lightweight, and features an intuitive tabbed interface for seamless data management.
microsoft office alternative - wps office

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.