Skip to main content

How to convert matrix style table to three columns in Excel?

Supposing you have a matrix-style table which contains column headings and row headings, and now you would like to convert this style table to three columns table, it also called list table as following screenshot shown, do you have any good ways to solve this problem in Excel?

Convert matrix style table to list with PivotTable

Convert matrix style table to list with VBA code

Convert matrix style table to list with Kutools for Excel

doc convert matrix to list 1


In Excel, there isn’t a direct feature for us to convert the matrix style table to three columns table, but, if you are familiar with PivotTable, it may do you a favor. Please do with the following steps:

1. Activate your worksheet which you want to use, then holding Alt + D, and then press P in the keyboard, in the popped out PivotTable and PivotChart Wizard dialog, select Multiple consolidation ranges under the Where is the data that you want to analyze section, and then choose PivotTable under the What kind of report do you want to create section, see screenshot:

doc convert matrix to list 2

2. Then click Next button, in the Step 2a of 3 wizard, select the I will create the page fields option, see screenshot:

doc convert matrix to list 3

3. Go on clicking Next button, in the Step 2b of 3 wizard, click doc convert matrix to list 5 button to select the data range that you want to convert, and then click Add button to add the data range to the All ranges list box, see screenshot:

doc convert matrix to list 4

4. And click Next button, in Step 3 of 3 wizard, select a location for the pivot table as you want.

doc convert matrix to list 6

5. Then click Finish button, a pivot table has been created at once, see screenshot:

doc convert matrix to list 7

6. In the pivot table, double click intersecting cell of the Grand Total, in this case, I will double click the cell F22, and it will generate a three columns table as following screenshot shown:

doc convert matrix to list 8

7. And finally, you can convert the table format to the normal range by selecting the table and then choose Table > Convert to Range from the context menu, see screenshot:

doc convert matrix to list 9


If you don’t like the first method, the following VBA code also can help you.

1. Press Alt + F11 to display the Microsoft Visual Basic for Applications window.

2. In the window, click Insert > Module to show a new module window, then copy and paste the following VBA code into the module window.

VBA code: Convert matrix style table to list

Sub ConvertTable()
'Update 20150512
Dim Rng As Range
Dim cRng As Range
Dim rRng As Range
Dim xOutRng As Range
xTitleId = "KutoolsforExcel"
Set cRng = Application.InputBox("Select your Column labels", xTitleId, Type:=8)
Set rRng = Application.InputBox("Select Your Row Labels", xTitleId, Type:=8)
Set Rng = Application.InputBox("Select your data", xTitleId, Type:=8)
Set outRng = Application.InputBox("Out put to (single cell):", xTitleId, Type:=8)
Set xWs = Rng.Worksheet
k = 1
xColumns = rRng.Column
xRow = cRng.Row
For i = Rng.Rows(1).Row To Rng.Rows(1).Row + Rng.Rows.Count - 1
    For j = Rng.Columns(1).Column To Rng.Columns(1).Column + Rng.Columns.Count - 1
        outRng.Cells(k, 1) = xWs.Cells(i, xColumns)
        outRng.Cells(k, 2) = xWs.Cells(xRow, j)
        outRng.Cells(k, 3) = xWs.Cells(i, j)
        k = k + 1
    Next j
Next i
End Sub

3. Then press F5 key to run this code, and a prompt box pops out to let you select the column labels of the data, see screenshot:

doc convert matrix to list 10

4. And then click OK button, in the next prompt box, select the row labels, see screenshot:

doc convert matrix to list 11

5. Go on clicking OK, then select the data range excluding the column and row headings in the prompt box, see screenshot:

doc convert matrix to list 12

6. And then click OK, in this dialog box, please select a cell where you want to locate the result. See screenshot:

doc convert matrix to list 13

7. At last, click OK, and you will get a three columns table at once.


Both of the above methods are somewhat troublesome, here, I will introduce you an easy way -- Kutools for Excel, with its Transpose Table Dimensions feature, you can quickly convert betwwen a matrix of cells and a list table.

Kutools for Excel : with more than 300 handy Excel add-ins, free to try with no limitation in 30 days

After installing Kutools for Excel, please do as following steps:

1. Click Kutools > Range > Transpose Table Dimensions, see screenshot:

2. In the Transpose Table Dimensions dialog box:

(1.) Choose Cross table to list option under Transpose type.

(2.) And then click doc convert matrix to list 5 button under Source range to select the data range that you want to convert.

(3.) Then click doc convert matrix to list 5 button under Results range to select a cell where you want to put the result.

doc convert matrix to list 15

3. And then click OK button, and you will get the following result which including the original cell formatting:

doc convert matrix to list 16

With this utility, you also convert flat list table to 2-dimensional cross table.

To know more about this Transpose Table Dimensions feature.

Download and free trial Kutools for Excel Now !


Kutools for Excel: with more than 300 handy Excel add-ins, free to try with no limitation in 30 days. Download and free trial Now!

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...

Description


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!
Comments (10)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Thanks for the tips. It's greatly saved my time and manual efforts.
This comment was minimized by the moderator on the site
Anybody know how to do this in a mac?
This comment was minimized by the moderator on the site
Sub ConvertTable_UseThis()

Dim Rng As Range
Dim cRng As Range
Dim rRng As Range
Dim xOutRng As Range
Dim xRng As Range, cRow As Integer, cCol As Integer


xTitleId = "Convert Table"
Set xRng = Application.Selection
Set xRng = Application.InputBox("Please select range:", "Number Range", Selection.Address, , , , , 8)
cRow = xRng.Rows.Count
cCol = xRng.Columns.Count


Set cRng = Range(xRng.Cells(1, 2), xRng.Cells(1, cCol))
Set rRng = Range(xRng.Cells(2, 1), xRng.Cells(cRow, 1))
Set Rng = Range(xRng.Cells(2, 2), xRng.Cells(cRow, cCol))
Set outRng = Application.InputBox("Out put to (single cell):", xTitleId, Type:=8)
Set xWs = Rng.Worksheet
k = 1
xColumns = rRng.Column
xRow = cRng.Row
For i = Rng.Rows(1).Row To Rng.Rows(1).Row + Rng.Rows.Count - 1
For j = Rng.Columns(1).Column To Rng.Columns(1).Column + Rng.Columns.Count - 1
outRng.Cells(k, 1) = xWs.Cells(i, xColumns)
outRng.Cells(k, 2) = xWs.Cells(xRow, j)
outRng.Cells(k, 3) = xWs.Cells(i, j)
k = k + 1
Next j
Next i
End Sub
This comment was minimized by the moderator on the site
For the VBA Code, one seems to really need this:xColumns = cRng.Column
xRow = rRng.Row
This comment was minimized by the moderator on the site
do you have a code with a tweak where the leftmost column of a selection is column labels and the topmost row of a selection is row labels?

Thanks in advance,
This comment was minimized by the moderator on the site
Sub ConvertTable_UseThis()

Dim Rng As Range
Dim cRng As Range
Dim rRng As Range
Dim xOutRng As Range
Dim xRng As Range, cRow As Integer, cCol As Integer


xTitleId = "Convert Table"
Set xRng = Application.Selection
Set xRng = Application.InputBox("Please select range:", "Number Range", Selection.Address, , , , , 8)
cRow = xRng.Rows.Count
cCol = xRng.Columns.Count


Set cRng = Range(xRng.Cells(1, 2), xRng.Cells(1, cCol))
Set rRng = Range(xRng.Cells(2, 1), xRng.Cells(cRow, 1))
Set Rng = Range(xRng.Cells(2, 2), xRng.Cells(cRow, cCol))
Set outRng = Application.InputBox("Out put to (single cell):", xTitleId, Type:=8)
Set xWs = Rng.Worksheet
k = 1
xColumns = rRng.Column
xRow = cRng.Row
For i = Rng.Rows(1).Row To Rng.Rows(1).Row + Rng.Rows.Count - 1
For j = Rng.Columns(1).Column To Rng.Columns(1).Column + Rng.Columns.Count - 1
outRng.Cells(k, 1) = xWs.Cells(i, xColumns)
outRng.Cells(k, 2) = xWs.Cells(xRow, j)
outRng.Cells(k, 3) = xWs.Cells(i, j)
k = k + 1
Next j
Next i
End Sub
This comment was minimized by the moderator on the site
Thanks a Ton, really appreciate the way you have explained. very useful
This comment was minimized by the moderator on the site
Thanks alot for this useful tool
This comment was minimized by the moderator on the site
Thanks, this was exactly what I was looking for. Awesome:)
This comment was minimized by the moderator on the site
what if i have 4 or more column?
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations