WRAPROWS Function in Google Sheets

Published on

This guide explains how to use the WRAPROWS function in Google Sheets, which is part of the suite of new functions introduced in early 2023, mostly under the “Array” category.

Purpose of the WRAPROWS Function

The WRAPROWS function wraps a given range of values (row or column) into multiple rows. Before WRAPROWS, there wasn’t a direct way to achieve this, and users had to rely on workarounds.

The difference between WRAPROWS and its counterpart, WRAPCOLS, is that WRAPROWS arranges values into rows, while WRAPCOLS arranges them into columns.

Syntax and Arguments

Syntax:

WRAPROWS(range, wrap_count, [pad_with])
  • range: The range of values to wrap (a single row or column).
  • wrap_count: The number of cells for each row in the output.
  • pad_with (optional): Specifies what to fill any extra cells with. If omitted, the default is #N/A.

Examples

Let’s explore some practical examples.

Transforming a Column into Rows with the WRAPROWS Function in Google Sheets
  1. Wrap a Range with 5 Cells Per Row:
    =WRAPROWS(A2:A11, 5)
    This will arrange the values from A2:A11 into rows with 5 values per row.
  2. Wrap a Range with 6 Cells Per Row:
    =WRAPROWS(A2:A11, 6)
    Since there are only 10 values, two #N/A errors appear in the second row.
  3. Wrap with 6 Cells Per Row and Handle Extra Cells:
    =WRAPROWS(A2:A11, 6, "x")
    Since the range has only 10 values, two extra cells will be filled with “x.”
  4. Exact Match of Wrap Count and Range:
    =WRAPROWS(A2:A11, 10)
    Here, the range has 10 values and is wrapped with exactly 10 cells per row, so no padding is needed.

Real-Life Application of WRAPROWS Function: Unstacking Data

One powerful use case of WRAPROWS is unstacking data. Suppose you have categories in column A and corresponding values in column B. If each category has the same number of rows, WRAPROWS can help you restructure the data into a more readable format.

Unstacking Data (Basic Level) in Google Sheets with the WRAPROWS Function

For instance:

In D3, use:

=UNIQUE(A2:A13)

In E3, use:

=WRAPROWS(B2:B13, 4)

This creates a table with unique categories and their corresponding values arranged horizontally.

To rearrange the output, you can combine functions like HSTACK and TRANSPOSE:

=TRANSPOSE(HSTACK(UNIQUE(A2:A13), WRAPROWS(B2:B13, 4)))

This formula transposes the combined output, making it easier to view.

Additional Tip: Expanding an Array with Empty Cells

If you’re an advanced Google Sheets user, you may need to add empty cells to array outputs, like shifting a dynamic calendar based on the day of the week. The WRAPROWS function can help with this.

For example, the formula below returns an array with 5 empty cells:

=IFNA(WRAPROWS(, 5))

You can combine this with an IF logical test to dynamically adjust the number of blank cells, offering great flexibility in various scenarios.

Handling Errors in the WRAPROWS Function

Common errors include:

  • #N/A: Appears if you omit the pad_with argument when there aren’t enough elements to fill the final row. You can customize this by specifying a value for pad_with.
  • #VALUE!: This error occurs if you mistakenly provide a 2D array to the WRAPROWS function, as it only accepts a single row or column as input.

This tutorial covers the essential use of the WRAPROWS function, providing practical examples and tips for handling errors and unstacking data.

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Expert Prashanth KV is a Diamond Product Expert in Google Sheets, officially recognized by Google for his contributions to the Docs Editors Help Community and featured in the Google Product Experts Directory. Explore his blog to learn advanced formulas, automation tips, and problem-solving techniques to elevate your spreadsheet skills.

Custom Order for QUERY Pivot Headers in Google Sheets

By default, when you use the PIVOT clause in a Google Sheets QUERY, the...

Calculate Trip Days by Month (Start, End, and Full Days) in Google Sheets

If you're managing business travel in Google Sheets, you may need to calculate how...

Mode of Comma-Separated Numbers in Excel (Dynamic Array)

There is no dedicated function in Excel to directly find the mode of comma-separated...

How to Find Mode of Comma-Separated Numbers in Google Sheets

Working with comma-separated numbers inside a single cell is a common scenario in Google...

More like this

Custom Order for QUERY Pivot Headers in Google Sheets

By default, when you use the PIVOT clause in a Google Sheets QUERY, the...

Calculate Trip Days by Month (Start, End, and Full Days) in Google Sheets

If you're managing business travel in Google Sheets, you may need to calculate how...

How to Find Mode of Comma-Separated Numbers in Google Sheets

Working with comma-separated numbers inside a single cell is a common scenario in Google...

2 COMMENTS

  1. Dear Prashanth,

    Thank you very much for your blog, which is a great inspiration and an excellent source for finding answers regarding the creative and effective use of Google Sheet functions.

    Regarding this article, especially the last section about using WRAPROWS to unstack:

    I am a little confused about the screenshot.

    With UNIQUE of columns A, we would determine the number of categories, i.e., the number of columns in the resulting table.

    At the same time, the number of elements per category is different. It seems like the wrapping creates an offset of 1 per row (3 vs. 4).

    Have a great day!

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.