跳到主要内容

如何在Excel中将矩阵转换为矢量或单列?

您是否曾经尝试在Excel中将单元格矩阵转换为单个行或列? 也许您可以复制一行或一列,然后将它们一个接一个地粘贴到单个向量中,但是,如果有多个行和列,这将很耗时。 在本文中,我将讨论一些有趣的方法,并希望它们对您有所帮助。

使用公式将单元格矩阵转换为单行或单列

使用 Kutools for Excel 将单元格矩阵转换为单行或单列


以下公式可以帮助您快速将矩阵转换为单行或单列。 请执行以下操作:

将单元格矩阵转换为单列

1。 首先,您应该为矩阵数据定义一个范围名称。 选择单元格的范围,然后在 姓名框 在编辑栏旁边,然后按 输入 键。 在这种情况下,我输入“ Matrix”作为定义名称,请参见屏幕截图:

doc将矩阵转换为第1列

2。 然后输入以下公式:

(1.)根据行将矩阵转换为单列,这意味着值是从每一行获取的,先后移动然后向下移动: = OFFSET(Matrix,TRUNC((ROW()-ROW($ G $ 1))/ COLUMNS(Matrix)),MOD(ROW()-ROW($ G $ 1),COLUMNS(Matrix)),1,1)(矩阵 是您在步骤1中定义的范围名称,并且 G1 是您输入此公式的单元格)。 然后将填充手柄拖动到单元格,直到显示0,请参见屏幕截图:

doc将矩阵转换为第2列

(2.)将矩阵转换为基于列的单列,这意味着值是从列中获取的,向下移动一列然后跨到右列: = OFFSET(矩阵,MOD(ROW()-ROW($ G $ 1),ROWS(矩阵)),TRUNC((ROW()-ROW($ G $ 1))/ ROWS(Matrix)),1,1) (矩阵 是您在步骤1中定义的范围名称,并且 G1 是您输入此公式的单元格)。 然后将填充手柄拖动到单元格,直到显示0,请参见屏幕截图:

doc将矩阵转换为第3列

将单元格矩阵转换为单行

要将单元格矩阵转换为单行,可以使用以下公式:

(1.)根据行将矩阵转换为单行,这意味着值是从每一行的左行到右行,然后向下移动到下一行: = OFFSET(Matrix,TRUNC((COLUMN()-COLUMN($ A $ 7))/ COLUMNS(Matrix)),MOD((COLUMN()-COLUMN($ A $ 7)),COLUMNS(Matrix)),1,1 ) (矩阵 是您为数据范围创建的范围名称,并且 A7 是您输入此公式的单元格)。 然后将填充手柄向右拖动到单元格,直到显示0,请参见屏幕截图:

doc将矩阵转换为第4列

(2.)根据列将矩阵转换为单行,这意味着从每一列获取值,向下移动一列然后跨到右列: = OFFSET(Matrix,MOD((COLUMN()-COLUMN($ A $ 7)),ROWS(Matrix)),TRUNC((COLUMN()-COLUMN($ A $ 7))/(ROWS(Matrix))),1,1 ,XNUMX) (矩阵 是您为数据范围创建的范围名称,并且 A7 是您输入此公式的单元格)。 然后将填充手柄向右拖动到单元格,直到显示0,请参见屏幕截图:

doc将矩阵转换为第5列


如果上述公式太长而无法记住,在这里,我可以推荐一个简单而强大的工具- Kutools for Excel,其 变换范围 实用程序,您可以根据需要快速将多个列和行转换为单个列或行。

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

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

1。 选择要转换的单元格矩阵。

2。 然后点击 库工具 > 范围 > 变换范围,请参见屏幕截图:

3。 在 变换范围 对话框中选择 范围到单列 如果要将矩阵转换为单列,或选择 范围到单行 如果要将矩阵转换为单行,请参见屏幕截图:

doc将矩阵转换为第07列

4。 然后点击 OK 按钮,然后弹出 变换范围 框,选择要放置结果的单元格,请参见屏幕截图:

doc将矩阵转换为第08列

5。 然后点击 OK 按钮,您选择的单元格矩阵已转换为单个行或列。

要了解有关此“变换范围”实用程序的更多信息。

 立即下载和免费试用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 (7)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Thanks much! Stacking a 2D matrix of data as a 1D column -> That was cool! Solved my problem precisely. Though I had to tweak the formula to get it right (I think the row and col are interchanged)... But the inspiration was from this article. Simply superb! Thanks!
This comment was minimized by the moderator on the site
Fantastic explanation - thank you. This helped me save hours of time
This comment was minimized by the moderator on the site
I'd like to accomplish this same task but with a range that is not so neatly defined. I've got wholes in the data and my matrix is spaced out over my spreadsheet rather than in a neatly define A1:D4 style block. Any ideas on how I can accomplish this?
This comment was minimized by the moderator on the site
Hi, Kevin:

The following VBA code can help you to combine the cells from a range:

Sub a()
Dim xSRg As Range
Dim xDRg As Range
Dim I As Long
Dim J As Long
Dim K As Long
Dim xArr
On Error Resume Next
Set xSRg = Application.InputBox("Please select the data range:", "KuTools for Excel", Selection.Address, , , , , 8)
If xSRg Is Nothing Then Exit Sub
Set xDRg = Application.InputBox("Select an output cell:)", "KuTools for Excel", , , , , , 8)
If xDRg Is Nothing Then Exit Sub
xArr = xSRg
K = 0
For I = 1 To UBound(xArr, 1)
For J = 1 To UBound(xArr, 2)
If xArr(I, J) <> "" Then
xDRg.Offset(K, 0).Value = xArr(I, J)
K = K + 1
End If
Next
Next
End Sub

Please try it, Hope it can help you!
This comment was minimized by the moderator on the site
Thank you!!!!
This comment was minimized by the moderator on the site
I had the same issue, put a filter on that column, and anything that has 0, filter out.
This comment was minimized by the moderator on the site
This is so useful! The formula to convert a matrix to single column based on column was exactly what I needed. Thank you!
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations