Excel 2024: Turn Data Sideways with a Formula


June 28, 2024 - by

Excel 2024: Turn Data Sideways with a Formula

Someone built this lookup table sideways, stretching across C1:N2. I realize that I could use HLOOKUP instead of VLOOKUP, but I prefer to turn the data back to a vertical orientation.

Copy C1:N2. Right-click in A4 and choose the Transpose option under the Paste Options. Transpose is the fancy Excel word for turn the data sideways.

Copy the horizontal lookup table in C1:N2. Right-click in a blank cell. The fourth icon under Paste Options is called Transpose. Choose that and you will paste a sideways copy of the original table.
Copy the horizontal lookup table in C1:N2. Right-click in a blank cell. The fourth icon under Paste Options is called Transpose. Choose that and you will paste a sideways copy of the original table.

I transpose a lot. But I use Alt+E, S, E, Enter to transpose instead of the right-click.


There is a problem, though. Transpose is a one-time snapshot of the data. What if you have formulas in the horizontal data? Is there a way to transpose with a formula? Yes, using the TRANSPOSE function. In the following image, use =TRANSPOSE(C2:N2). The new =WRAPCOLS(C2:N2,1) will also produce the same result.

If you don't have Microsoft 365 and you don't have access to the dynamic array formulas, you can use a combination of INDEX and ROW, as shown in the figure below. =ROW(1:1) is a clever way of writing the number 1. As you copy this formula down, the row reference changes to 2:2 and returns a 2.

The INDEX function says you are getting the answers from C2:N2, and you want the nth item from the range.

A different solution that does not require Ctrl+Shift+Enter. The formula for January in B4 is =INDEX($C$2:$N$2,ROW(1:1)). The ROW(1:1) is a complicated way to write the number 1.
A different solution that does not require Ctrl+Shift+Enter. The formula for January in B4 is =INDEX($C$2:$N$2,ROW(1:1)). The ROW(1:1) is a complicated way to write the number 1.

In the figure below, =FORMULATEXT in column C shows how the formula changes when you copy down.

As you copy that formula down, the reference to ROW(1:1) automatically changes to ROW(2:2) and so on.
As you copy that formula down, the reference to ROW(1:1) automatically changes to ROW(2:2) and so on.


Bonus Tip: Protect Rows with an Old-Style Array Formula

Here is an odd use for an array formula: Say that you don't want anyone to delete or insert any rows in one section of a worksheet. Scroll far to the right, off the screen, and build an array in those rows. Select Z1:Z9. Type =2 and press Ctrl+Shift+Enter. You can use any number, =0, =1, =2, and so on.

Instructions on the worksheet ask people not to delete any rows. Someone will try to delete a row. Off to the right, select Z1:Z8. Type =2 and press Ctrl+Shift+Enter. This creates an array in those rows.
Instructions on the worksheet ask people not to delete any rows. Someone will try to delete a row. Off to the right, select Z1:Z8. Type =2 and press Ctrl+Shift+Enter. This creates an array in those rows.

If someone tries to delete a row, Excel prevents it and shows a cryptic message about arrays, shown below.

When someone tries to delete a row in the area of rows 1 to 8, a message will appear with "You Can't Change Part Of an Array."
When someone tries to delete a row in the area of rows 1 to 8, a message will appear with "You Can't Change Part Of an Array."

Thanks to Excel Ace and Tracia Williams for suggesting this feature.


This article is an excerpt from MrExcel 2024 Igniting Excel

Title photo by Thom Milkovic on Unsplash