Skip to main content
 

How to transpose / convert columns and rows into single row?

Author: Xiaoyang Last Modified: 2024-07-29

How to join multiple rows and columns into a single long row? Maybe, it seems easy for you, because you can copy them one by one and join them into a row manually. But it will be time consuming and tedious if there are hundreds of rows and columns. Here I will talk about some quick tricks to solve it.

Transpose / Convert columns and rows into single row with formula

Transpose / Convert columns and rows into single row with VBA code

Transpose / Convert columns and rows into single row with Kutools for Excel


Transpose / Convert columns and rows into single row with formula

Supposing you have a range of data as following screenshot shows, you can convert the range data into one row in a new worksheet with a long formula.

doc-convert-range-to-row1

Please apply the formula as this:

1. In a new worksheet of the active workbook, click cell A1, copy and paste this formula: =OFFSET(Sheet1!$A$1,((ROW()-1)*5)+(FLOOR(COLUMN()-1,4)/4),(COLUMN()-1)-(FLOOR(COLUMN()-1,4)))

Note: Sheet1!$A$1 is the worksheet and range references that you want to use.

ROW()-1)*5 in the above formula, 5 stands for the row number; and COLUMN()-1,4)/4, the 4 stands for the column number. You can change them as your need.

2. Then drag the fill handle over to right until number 0 is appeared. In this case, all the data in the range has been transposed into a single row in a new worksheet. See screenshot:

doc-convert-range-to-row2


Transpose / Convert columns and rows into single row with VBA code

The following VBA code also can help you convert a range of data to one row.

1. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.

2. Click Insert > Module, and paste the following code in the Module window.

Sub TransformOneRow()
'Updateby20131120
Dim InputRng As Range, OutRng As Range
xTitleId = "KutoolsforExcel"
Set InputRng = Application.Selection
Set InputRng = Application.InputBox("Ranges to be transform :", xTitleId, InputRng.Address, Type:=8)
Set OutRng = Application.InputBox("Paste to (single cell):", xTitleId, Type:=8)
Application.ScreenUpdating = False
xRows = InputRng.Rows.Count
xCols = InputRng.Columns.Count
For i = 1 To xRows
    InputRng.Rows(i).Copy OutRng
    Set OutRng = OutRng.Offset(0, xCols + 0)
Next
Application.ScreenUpdating = True
End Sub

3. Then press F5 key to run the code, a dialog is popped out for you to select a range of contents you want to convert into a row, and click Ok, another popped-up dialog is for you to select a single cell to put out the result. See screenshots:

screenshot of converting range to row with VBA
screenshot of converting range to row with VBA arrow
screenshot of converting range to row with VBA 2

Then Click Ok, the contents in the selected range are converted into a row. See screenshot:

screenshot of converting range to row with VBA original data
screenshot of converting range to row with VBA arrow 2
screenshot of converting range to row with VBA result

Note: In Set OutRng = OutRng.Offset(0, xCols + 0), you can change 0 to any number to meet your need.

For exampel, if you want to separate the results accroding to the original rows by one column, you can change Set OutRng = OutRng.Offset(0, xCols + 0) to Set OutRng = OutRng.Offset(0, xCols + 1), the results are shown as following:

screenshot of converting range to row with VBA example


Transpose / Convert columns and rows into single row with Kutools for Excel

It seems the above two methods are somewhat difficult for us Excel beginner, here I will talk about a handy tool-Kutools for Excel for you.

Kutools for Excel includes more than 300 handy Excel tools. Free to try with no limitation in 30 days. Get it Now

With the utility Transform Range of Kutools for Excel, you can quickly transform a range to a single row, please do as follows:

1. Select the range that you want to transpose.

2. Click KutoolsRange > Transform Range.

3. In the Transform Range dialog box, select Range to single row option, see screenshot:

screenshot of converting range to row with kutools for Excel dialog

4. Then click OK, and click a cell to put the result from the pop out box.

screenshot of converting range to row with kutools for Excel output range dialog

5. Click OK, and the data in the range has been transposed into a single row. See screenshots:

doc-convert-range-to-row1
-1
doc-convert-range-to-row7

If you want to know more about this feature, please visit Transform Range.


Related articles:

How to change row to column in Excel?

How to transpose / convert a single column to multiple columns in Excel?

How to transpose / convert columns and rows into single column?

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!