跳到主要内容

如何将每5或n行从一列转置为多列?

doc每5行转置1

假设您在A列中有较长的数据,现在,您想将A列中的每5行转置为多列,例如将A1:A5转换为C6:G6,将A6:A10转换为C7:G7,依此类推显示以下截图。 如果不在Excel中重复复制和粘贴,如何处理此任务?

使用公式将每5或n行从一列转置为多列

使用VBA代码将每5或n行从一列转置为多列

使用 Kutools for Excel 将每 5 行或 n 行从一列转置为多列


在Excel中,您可以应用以下公式将每n行从一列转置为多列,请执行以下操作:

1。 例如,将以下公式输入到要将结果放入C1的空白单元格中, = INDEX($ A:$ A,ROW(A1)* 5-5 + COLUMN(A1)),请参见屏幕截图:

doc每5行转置2

备注:在以上公式中, 答: 是您要转置的列引用,并且 A1 是已使用列的第一个单元格,即数字 5 表示您的数据将定位的列数,您可以根据需要进行更改。 并且列表的第一个单元格必须位于工作表的第一行。

2。 然后将填充手柄向右拖动到五个单元格,然后继续将填充手柄向下拖动到单元格范围,直到显示0,请参见屏幕截图:

doc每5行转置3


将每5或n行从一列转换为多列:

要将每5或n行从一列转换为多列, Kutools for Excel's 变换范围 实用程序可以帮助您尽快解决此工作。 它还可以帮助您将一系列数据转置为单个行或列。 点击下载Kutools for Excel!

doc每5行转置10

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


如果您无法正确应用公式,则以下VBA代码也可以为您提供帮助。

1。 按住 ALT + F11 键打开 Microsoft Visual Basic应用程序 窗口。

2。 点击 插页 > 模块,然后将以下代码粘贴到 模块 窗口。

VBA代码:将每5或n行从一列转置为多列:

Public Sub TransposeData()
'updateby Extendoffice
    Dim xLRow As Long
    Dim xNRow As Long
    Dim i As Long
    Dim xUpdate As Boolean
    Dim xRg As Range
    Dim xOutRg As Range
    Dim xTxt As String
    On Error Resume Next
    xTxt = ActiveWindow.RangeSelection.Address
    Set xRg = Application.InputBox("Please select data range(only one column):", "Kutools for Excel", xTxt, , , , , 8)
    Set xRg = Application.Intersect(xRg, xRg.Worksheet.UsedRange)
    If xRg Is Nothing Then Exit Sub
    If (xRg.Columns.Count > 1) Or _
       (xRg.Areas.Count > 1) Then
        MsgBox "the used range only contain one column", , "Kutools for Excel"
        Exit Sub
    End If
    Set xOutRg = Application.InputBox("please select output range(specify one cell):", "Kutools for Excel", xTxt, , , , , 8)
    If xOutRg Is Nothing Then Exit Sub
    Set xOutRg = xOutRg.Range(1)
    xUpdate = Application.ScreenUpdating
    Application.ScreenUpdating = False
    xLRow = xRg.Rows.Count
    For i = 1 To xLRow Step 5
        xRg.Cells(i).Resize(5).Copy
        xOutRg.Offset(xNRow, 0).PasteSpecial Paste:=xlPasteAll, Transpose:=True
        xNRow = xNRow + 1
    Next
    Application.ScreenUpdating = xUpdate
End Sub

3。 粘贴代码后,请按 F5 键运行它,然后会弹出一个提示框,提醒您选择要转置的列,请参见屏幕截图:

doc每5行转置4

4。 然后点击 OK,然后选择一个要在其中弹出结果框的单元格,请参见屏幕截图:

doc每5行转置5

5。 并点击 OK,该列中的数据已转换为所需的五列,请参见屏幕截图:

doc每5行转置6

备注:在上面的代码中,您可以更改数字 5 到您需要的其他号码。


如果你有 Kutools for Excel,其 变换范围 实用程序,您可以快速将一列或一行转置为多列和多行。

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

安装后 Kutools for Excel,请执行以下操作:

1。 在列中选择数据,然后单击 库工具 > 范围 > 变换范围,请参见屏幕截图:

2。 在 变换范围 对话框中选择 单列到范围 选项下 转换类型,然后检查 固定值 在下面 每条记录行,然后在中指定要转置到的列数 固定值 框,请参见屏幕截图:

doc每5行转置8

3。 然后点击 Ok 按钮,在弹出的框中,请选择一个单元格以输出结果,请参见屏幕截图:

doc每5行转置9

4。 然后点击 OK 按钮,并且您的列数据已每5行转置一次,如下所示的屏幕截图:

doc每5行转置6

立即下载和免费试用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 (15)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
Bonjour,

J'ai, dans mon unique colonne de données, des cellules placées aléatoirement toutes les x lignes et qui contiennent une suite de caractères.

Je voudrait que cette cellule soit dans la première colonne de la ligne transposée, avec, dans les colonnes suivantes, la transposition des lignes qui la suivent, jusqu'à la répétition de ma chaine de caractères, qui signifierait le début de la ligne suivante...

Bref, Heeelllp...

Merci d'avance
Stéphane
This comment was minimized by the moderator on the site
You're a genius. Thanks!
Rated 5 out of 5
This comment was minimized by the moderator on the site
I try doing this just as written, and all I get is Error:508
This comment was minimized by the moderator on the site
Hi, How to do this for Colms to rows. Thank you
This comment was minimized by the moderator on the site
I've rewritten the command to this one:
=INDEX($A:$A,ROW(A1)+((COLUMN(A1)-2)*5))
This executes it inverted.
So:
1
2
3
4
5
6
7
8
9
...
becomes
1, 6
2, 7
3, 8
4, 9
5, ...
This comment was minimized by the moderator on the site
Thanks alot _/\_ Awesome job with =INDEX($A:$A,ROW(B1)*5-5+COLUMN(B1))
worked perfectly
This comment was minimized by the moderator on the site
I tried only the the formula option and it worked great. Till now have been using (Transpose formula with ctrl+shift+enter) but there the disadvantage for we have delete many extra rows. when the rows to be transposed for large in the order of lakhs, then deleting them in excel is either impossible or takes a lot of time.
this approach made the life easier by only copying the required rows... Thanks
This comment was minimized by the moderator on the site
This is fricking AWESOME!!! Thank you SO much. Your example was exactly what I needed and it worked beautifully.
This comment was minimized by the moderator on the site
=INDEX($A:$A,ROW(A1)*5-5+COLUMN(A1))
It was very simple and really useful. Thank you so much
This comment was minimized by the moderator on the site
It was great! Thank you! You saved me hours of manual work!
This comment was minimized by the moderator on the site
Thank you so much! It was really helpful. :)
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations