跳到主要內容

如何在Excel中將矩陣樣式表轉換為三列?

假設您有一個包含列標題和行標題的矩陣樣式表,現在您想將此樣式表轉換為三列表,也稱為列表表,如下面的屏幕快照所示,您是否有解決這個問題的任何好方法Excel中的問題?

使用數據透視表將矩陣樣式表轉換為列表

使用VBA代碼將矩陣樣式表轉換為列表

使用Kutools for Excel將矩陣樣式表轉換為列表

doc將矩陣轉換為列表1


在Excel中,沒有將矩陣樣式表轉換為三列表的直接功能,但是,如果您熟悉PivotTable,它可能會對您有所幫助。 請執行以下步驟:

1。 激活您要使用的工作表,然後按住 ALT + D,然後按 P 在鍵盤上,在彈出 數據透視表和數據透視圖嚮導 對話框中選擇 多種合併範圍您要分析的數據在哪裡 部分,然後選擇 數據透視表您要創建哪種報告 部分,請參見屏幕截圖:

doc將矩陣轉換為列表2

2。 然後點擊 下一頁 按鈕,在 第2a步,共3步 嚮導中,選擇 我將創建頁面字段 選項,請參見屏幕截圖:

doc將矩陣轉換為列表3

3。 繼續點擊 下一頁 按鈕,在 第2b步,共3步 嚮導,點擊 doc將矩陣轉換為列表5 按鈕以選擇要轉換的數據范圍,然後單擊 加入 按鈕將數據范圍添加到 所有範圍 列錶框,請參見屏幕截圖:

doc將矩陣轉換為列表4

4。 並點擊 下一頁 按鈕,在 步驟3 3的 嚮導中,根據需要選擇數據透視表的位置。

doc將矩陣轉換為列表6

5。 然後點擊 按鈕,即可立即創建數據透視表,請參見屏幕截圖:

doc將矩陣轉換為列表7

6。 在數據透視表中,雙擊“總計”的相交單元格,在這種情況下,我將雙擊單元格F22,它將生成一個三列的表,如以下屏幕截圖所示:

doc將矩陣轉換為列表8

7。 最後,您可以通過選擇表格將表格格式轉換為正常範圍,然後選擇 枱燈 > 轉換為範圍 從上下文菜單中,查看屏幕截圖:

doc將矩陣轉換為列表9


如果您不喜歡第一種方法,則以下VBA代碼也可以為您提供幫助。

1。 按 Alt + F11鍵 顯示 Microsoft Visual Basic for Applications 窗口。

2。 在窗口中,單擊 插入 > 模塊 以顯示一個新的模塊窗口,然後將以下VBA代碼複製並粘貼到模塊窗口中。

VBA代碼:將矩陣樣式表轉換為列表

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。 然後按 F5 鍵以運行此代碼,並彈出一個提示框,讓您選擇數據的列標籤,請參見屏幕截圖:

doc將矩陣轉換為列表10

4。 然後點擊 OK 按鈕,在下一個提示框中,選擇行標籤,請參見屏幕截圖:

doc將矩陣轉換為列表11

5。 繼續點擊 OK,然後在提示框中選擇除列標題和行標題之外的數據范圍,請參見屏幕截圖:

doc將矩陣轉換為列表12

6。 然後點擊 OK,請在此對話框中選擇要在其中查找結果的單元格。 看截圖:

doc將矩陣轉換為列表13

7。 最後點擊 OK,您將立即獲得一個三列的表格。


以上兩種方法都有些麻煩,在這裡,我將為您介紹一個簡單的方法- Excel的Kutools,其 轉置台尺寸 功能,您可以在單元格矩陣和列表表之間快速轉換。

Excel的Kutools : 帶有300多個便捷的Excel加載項,可以在30天內免費試用

安裝後 Excel的Kutools,請執行以下步驟:

1。 點擊 庫工具 > 範圍 > 轉置台尺寸,請參見屏幕截圖:

2。 在 轉置台尺寸 對話框:

(1.)選擇 交叉表列出 選項下 轉置類型.

(2.)然後單擊 doc將矩陣轉換為列表5 按鈕下 源範圍 選擇要轉換的數據范圍。

(3.)然後單擊 doc將矩陣轉換為列表5 按鈕下 結果範圍 選擇要放置結果的單元格。

doc將矩陣轉換為列表15

3。 然後點擊 OK 按鈕,您將獲得以下結果,其中包括原始單元格格式:

doc將矩陣轉換為列表16

使用此實用程序,您還可以 將平面列表轉換為二維交叉表.

要了解有關此轉置表維功能的更多信息。

立即下載和免費試用Excel的Kutools!


Excel的Kutools:具有300多個方便的Excel加載項,可以在30天內免費試用,沒有任何限制。 立即下載並免費試用!

最佳辦公生產力工具

🤖 Kutools 人工智慧助手:基於以下內容徹底改變數據分析: 智慧執行   |  生成代碼  |  建立自訂公式  |  分析數據並產生圖表  |  呼叫 Kutools 函數...
熱門特色: 尋找、突出顯示或識別重複項   |  刪除空白行   |  合併列或儲存格而不遺失數據   |   沒有公式的回合 ...
超級查詢: 多條件VLookup    多值VLookup  |   跨多個工作表的 VLookup   |   模糊查詢 ....
高級下拉列表: 快速建立下拉列表   |  依賴下拉列表   |  多選下拉列表 ....
欄目經理: 新增特定數量的列  |  移動列  |  切換隱藏列的可見性狀態  |  比較範圍和列 ...
特色功能: 網格焦點   |  設計圖   |   大方程式酒吧    工作簿和工作表管理器   |  資源庫 (自動文字)   |  日期選擇器   |  合併工作表   |  加密/解密單元格    按清單發送電子郵件   |  超級濾鏡   |   特殊過濾器 (過濾粗體/斜體/刪除線...)...
前 15 個工具集12 文本 工具 (添加文本, 刪除字符,...)   |   50+ 圖表 類型 (甘特圖,...)   |   40+ 實用 公式 (根據生日計算年齡,...)   |   19 插入 工具 (插入二維碼, 從路徑插入圖片,...)   |   12 轉化 工具 (數字到單詞, 貨幣兌換,...)   |   7 合併與拆分 工具 (高級合併行, 分裂細胞,...)   |   ... 和更多

使用 Kutools for Excel 增強您的 Excel 技能,體驗前所未有的效率。 Kutools for Excel 提供了 300 多種進階功能來提高生產力並節省時間。  點擊此處獲取您最需要的功能...

產品描述


Office選項卡為Office帶來了選項卡式界面,使您的工作更加輕鬆

  • 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,發布者,Access,Visio和Project。
  • 在同一窗口的新選項卡中而不是在新窗口中打開並創建多個文檔。
  • 將您的工作效率提高 50%,每天為您減少數百次鼠標點擊!
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