EXPAND Function¶
The EXPAND function in Excel is used to expand an array to specified dimensions by adding rows and/or columns. When an array is expanded, empty positions are filled with a specified pad value (or #N/A by default).
Key Features of EXPAND:¶
- Expands an array to a larger number of rows and/or columns.
- Fills new positions with a customizable pad value.
- If no pad value is specified, new cells contain
#N/A. - Works seamlessly with other dynamic array functions.
- Useful for aligning arrays of different sizes for calculations.
Syntax:¶
- array: The array or range to expand.
- rows: The number of rows in the expanded array. Must be greater than or equal to the current number of rows. Use
#N/Aor omit to keep the current row count. - columns (optional): The number of columns in the expanded array. Must be greater than or equal to the current number of columns. If omitted, the current column count is kept.
- pad_with (optional): The value to fill in new cells. If omitted,
#N/Ais used.
How EXPAND Works:¶
- The function takes the original array and increases its dimensions to match the specified rows and columns.
- The original data remains in the top-left portion of the expanded array.
- New cells created by the expansion are filled with the
pad_withvalue. - If
rowsorcolumnsis less than the array's current dimensions, a#VALUE!error is returned. - If the array is already the specified size, it is returned unchanged.
Examples:¶
1. Expand a 2x2 Array to 4x4 with Default Padding:¶
Result:
2. Expand with a Custom Pad Value (Zero):¶
Result:
3. Expand Only Rows:¶
Result:
4. Expand Only Columns:¶
Result:
5. Expand a Single Cell to Create a Filled Array:¶
Result:
6. Combine with SEQUENCE for Padded Arrays:¶
Result:
7. Expand a Range to Match Another Array's Size:¶
Result:
8. Use with Text Padding:¶
Result:
Notes:¶
EXPANDis available in Excel 365 and Excel 2021 or later versions.- If
rowsis less than the array's row count orcolumnsis less than the column count, Excel returns a#VALUE!error. - Using
#N/Aforrowsorcolumnskeeps the original dimension unchanged. - The
pad_withvalue can be a number, text, logical value, or error value. EXPANDdoes not modify the original data; it creates a new expanded array.
Applications:¶
- Array Alignment: Match array sizes before performing element-wise operations.
- Data Padding: Fill sparse data with default values for calculations.
- Matrix Operations: Create uniformly sized matrices for mathematical operations.
- Report Formatting: Ensure consistent table dimensions in dynamic reports.
- Combining Data: Prepare arrays of different sizes for HSTACK or VSTACK operations.
Related Functions:¶
- DROP: Excludes a specified number of rows or columns from an array.
- TAKE: Extracts a specified number of rows or columns from an array.
- HSTACK: Horizontally combines arrays side by side.
- VSTACK: Vertically stacks arrays on top of each other.
- CHOOSECOLS: Returns specified columns from an array.
- CHOOSEROWS: Returns specified rows from an array.
- WRAPCOLS: Wraps a row or column into a 2D array by columns.
- WRAPROWS: Wraps a row or column into a 2D array by rows.
Tip: Use
EXPANDwith a pad value of 0 when preparing arrays for mathematical operations likeMMULT, where consistent dimensions are required. This ensures all arrays align properly without introducing#N/Aerrors in calculations.