xRow = rRng.Row
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?
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:
2. Then click Next button, in the Step 2a of 3 wizard, select the I will create the page fields option, see screenshot:
3. Go on clicking Next button, in the Step 2b of 3 wizard, click 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:
4. And click Next button, in Step 3 of 3 wizard, select a location for the pivot table as you want.
5. Then click Finish button, a pivot table has been created at once, see screenshot:
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:
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:
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:
4. And then click OK button, in the next prompt box, select the row labels, see screenshot:
5. Go on clicking OK, then select the data range excluding the column and row headings in the prompt box, see screenshot:
6. And then click OK, in this dialog box, please select a cell where you want to locate the result. See screenshot:
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 button under Source range to select the data range that you want to convert.
(3.) Then click button under Results range to select a cell where you want to put the result.
3. And then click OK button, and you will get the following result which including the original cell formatting:
With this utility, you also convert flat list table to 2-dimensional cross table.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
- To post as a guest, your comment is unpublished.· 5 days agoFor the VBA Code, one seems to really need this:xColumns = cRng.Column
xRow = rRng.Row
- To post as a guest, your comment is unpublished.· 3 months agodo 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,
- To post as a guest, your comment is unpublished.· 10 months agoThanks a Ton, really appreciate the way you have explained. very useful
- To post as a guest, your comment is unpublished.· 1 years agoThanks alot for this useful tool
- To post as a guest, your comment is unpublished.· 3 years agoThanks, this was exactly what I was looking for. Awesome:)
- To post as a guest, your comment is unpublished.· 4 years agowhat if i have 4 or more column?