# Rearrange values in a cell range to a single column

This article demonstrates formulas that rearrange values in a cell range to a single column.

#### Table of Contents

- Rearrange cells in a cell range to vertically distributed values (Excel formula)
- How to quickly create a named range
- Explaining array formula in cell B2
- Rearrange cells in a cell range to vertically distributed values (Excel 2019)
- Explaining array formula (Excel 2019)
- Returning values row by row
- Get Excel file

## 1. Rearrange cells in a cell range to vertically distributed values (Excel formula)

The formula in cell B8 uses a named range to calculate the row and column needed to extract the correct value.

## 2. How to quickly create a named range

This step is optional, you can use just as well use a cell reference.

To create a named range simply select the cell range (B3:E5) and press with left mouse button on in the name box. Type a name for that range, I named the cell range rng. Press Enter, that's it.

## 3. Explaining formula in cell B8

#### Step 1 - Count rows in cell range

The INDEX function needs a row and column number in order to get the correct value.

The ROWS function returns the number of rows in a cell range.

ROWS(rng) becomes ROWS(B3:E5) and returns 3.

#### Step 2 - Create a sequence

The ROW function returns the row number of a cell reference.

ROW(A1) returns 1.

#### Step 3 - Create a repeating number sequence

To calculate the row number I use the MOD function to build a repeating number sequence. There are three rows in B3:E5 so the sequence must be 1,2,3,1,2,3, ... and so on.

MOD(ROW(A1)-1, ROWS(rng))+1

becomes

MOD(1-1, 3)+1

becomes

MOD(0, 3) + 1 and returns 1.

#### Step 4 - Create a repeating number sequence for columns

To calculate the column number I use the QUOTIENT function to build a repeating number sequence: 1,1,1,2,2,2,3 ... and so on.

QUOTIENT(ROW(A1)-1, ROWS(rng))+1

becomes

QUOTIENT(1-1, 3)+1

becomes

QUOTIENT(0, 3)+1 and returns 1.

#### Step 5 - Get value based on row and column numbers

The INDEX function then returns the value in row 1 and column 1 from cell range 3:E5.

INDEX(rng, MOD(ROW(A1)-1, ROWS(rng))+1, QUOTIENT(ROW(A1)-1, ROWS(rng))+1)

becomes

INDEX(rng, 1, 1)

and returns "Veges are us" in cell B8.

## 4. Rearrange cells in a cell range to vertically distributed values (Excel 2019 formula)

Array formula in cell B8:

Note, enter this formula as a regular formula if you are an Excel 365 user.

## 5. Explaining array formula (Excel 2019)

#### Step 1 - Join values using a delimiting character

The TEXTJOIN function joins values from a cell range or array, you need at least the Excel 2019 version.

TEXTJOIN(delimiter, ignore_empty, text1, [text2], ...)

I recommend using a delimiting character that is not in cell range B3:E5 to avoid confusion.

TEXTJOIN("|", TRUE, B3:E5)

becomes

TEXTJOIN("|",TRUE,{"Veges are us","Cucumber",1.2,"Green";"Food inc.","Tomato",0.5,"Red";"Eat more Corp","Lettuce",0.9,"Green"})

and returns

"Veges are us|Cucumber|1.2|Green|Food inc.|Tomato|0.5|Red|Eat more Corp|Lettuce|0.9|Green"

#### Step 2 - Substitute delimiting character with XML tag

The SUBSTITUTE function substitutes a specific text string in a value.

SUBSTITUTE(*text, old_text, new_text, [instance_num]*)

SUBSTITUTE(TEXTJOIN("|", TRUE, B3:E5), "|","</B><B>")

becomes

SUBSTITUTE("Veges are us|Cucumber|1.2|Green|Food inc.|Tomato|0.5|Red|Eat more Corp|Lettuce|0.9|Green", "|","</B><B>")

and returns

"Veges are us</B><B>Cucumber</B><B>1.2</B><B>Green</B><B>Food inc.</B><B>Tomato</B><B>0.5</B><B>Red</B><B>Eat more Corp</B><B>Lettuce</B><B>0.9</B><B>Green"

#### Step 3 - Concatenate string with XML tag

The ampersand character & lets you concatenate strings in an Excel formula.

"<A><B>"&SUBSTITUTE("Veges are us|Cucumber|1.2|Green|Food inc.|Tomato|0.5|Red|Eat more Corp|Lettuce|0.9|Green", "|","</B><B>")&"</B></A>"

becomes

"<A><B>"&"Veges are us</B><B>Cucumber</B><B>1.2</B><B>Green</B><B>Food inc.</B><B>Tomato</B><B>0.5</B><B>Red</B><B>Eat more Corp</B><B>Lettuce</B><B>0.9</B><B>Green"&"</B></A>"

and returns

"<A><B>Veges are us</B><B>Cucumber</B><B>1.2</B><B>Green</B><B>Food inc.</B><B>Tomato</B><B>0.5</B><B>Red</B><B>Eat more Corp</B><B>Lettuce</B><B>0.9</B><B>Green</B></A>"

#### Step 4 - Extract values from XML data

The FILTERXML function extracts specific values from XML content by using the given xpath.

FILTERXML(xml, xpath)

FILTERXML("<A><B>"&SUBSTITUTE(TEXTJOIN("|", TRUE, B3:E5), "|","</B><B>")&"</B></A>","//B")

becomes

FILTERXML("<A><B>Veges are us</B><B>Cucumber</B><B>1.2</B><B>Green</B><B>Food inc.</B><B>Tomato</B><B>0.5</B><B>Red</B><B>Eat more Corp</B><B>Lettuce</B><B>0.9</B><B>Green</B></A>","//B")

and returns

{"Veges are us"; "Cucumber"; 1.2; "Green"; "Food inc."; "Tomato"; 0.5; "Red"; "Eat more Corp"; "Lettuce"; 0.9; "Green"}.

## 6. Returning values row by row

The following formula gets the values row by row:

How to use the COLUMN function

The COLUMN function returns the column number of the top-left cell of a cell reference. If the argument is not […]

Search values distributed horizontally and return corresponding value

Question: Hi, The formula here works great but I can't figure out how to change it to work with data […]

Filter shared records from two tables

I will in this blog post demonstrate a formula that extracts common records (shared records) from two data sets in […]

How to use the COLUMNS function

The COLUMNS function allows you to calculate the number of columns in a cell range. The example above shows that cell […]

Gets a value in a specific cell range based on a row and column number.

The Mod function returns the remainder after a number is divided by a divisor. The Mod function is short for […]

Sort items by adjacent number in every other value

This article demonstrates a formula that sorts items arranged horizontally based on the adjacent numbers, every other column contains a […]

Can someone explain to me why this happens? This example is working. FREQUENCY function returns {2; 1; 1}. 2 values (0.1 and […]

The Mod function returns the remainder after a number is divided by a divisor. The Mod function is short for […]

How to create a list of random unique numbers

Question: How do I create a random list of unique numbers from say 1 to 10, without using VBA and […]

Count overlapping days in multiple date ranges

The MEDIAN function lets you count overlapping dates between two date ranges. If you have more than two date ranges […]

The ROW function calculates the row number of a cell reference. Excel Function Syntax ROW(reference) Arguments reference Optional. A reference […]

The ROWS function allows you to calculate the number of rows in a cell range. The example above shows that cell […]

### Leave a Reply

### How to comment

**How to add a formula to your comment**

<code>Insert your formula here.</code>

**Convert less than and larger than signs**

Use html character entities instead of less than and larger than signs.

< becomes < and > becomes >

**How to add VBA code to your comment**

[vb 1="vbnet" language=","]

Put your VBA code here.

[/vb]

**How to add a picture to your comment:**

Upload picture to postimage.org or imgur

Paste image link to your comment.

**Contact Oscar**

You can contact me through this contact form