跳到主要内容

如何在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 向导中,根据需要选择数据透视表的位置。

doc将矩阵转换为列表6

5。 然后点击 完成 按钮,即可立即创建数据透视表,请参见屏幕截图:

doc将矩阵转换为列表7

6。 在数据透视表中,双击“总计”的相交单元格,在这种情况下,我将双击单元格F22,它将生成一个三列的表,如以下屏幕截图所示:

doc将矩阵转换为列表8

7。 最后,您可以通过选择表格将表格格式转换为正常范围,然后选择 > 转换为范围 从上下文菜单中,查看屏幕截图:

doc将矩阵转换为列表9


如果您不喜欢第一种方法,则以下VBA代码也可以为您提供帮助。

1。 按 Alt + F11键 显示 Microsoft Visual Basic应用程序 窗口。

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,您将立即获得一个三列的表格。


以上两种方法都有些麻烦,在这里,我将为您介绍一个简单的方法- Kutools for Excel,其 转置台尺寸 功能,您可以在单元格矩阵和列表表之间快速转换。

Kutools for Excel : 带有300多个便捷的Excel加载项,可以在30天内免费试用

安装后 Kutools for Excel,请执行以下步骤:

1。 点击 库工具 > 范围 > 转置台尺寸,请参见屏幕截图:

2。 在 转置台尺寸 对话框:

(1.)选择 交叉表列出 选项下 转置类型.

(2.)然后单击 doc将矩阵转换为列表5 按钮下 源范围 选择要转换的数据范围。

(3.)然后单击 doc将矩阵转换为列表5 按钮下 结果范围 选择要放置结果的单元格。

doc将矩阵转换为列表15

3。 然后点击 OK 按钮,您将获得以下结果,其中包括原始单元格格式:

doc将矩阵转换为列表16

使用此实用程序,您还可以 将平面列表转换为二维交叉表.

要了解有关此转置表维功能的更多信息。

立即下载和免费试用Excel的Kutools!


Kutools for Excel:具有300多个方便的Excel加载项,可以在30天内免费试用,没有任何限制。 立即下载并免费试用!

最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。  单击此处获取您最需要的功能...

产品描述


Office Tab 为 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