Note: The other languages of the website are Google-translated. Back to English
登陆  \/ 
x
or
x
点此注册  \/ 
x

or

如何将每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。 在列中选择数据,然后单击 Kutools > Range > 变换范围,请参见屏幕截图:

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

doc每5行转置8

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

doc每5行转置9

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

doc每5行转置6

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


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

最佳办公效率工具

Kutools for Excel解决了您的大多数问题,并使您的生产率提高了80%

  • 重用: 快速插入 复杂的公式,图表 以及您以前使用过的任何东西; 加密单元 带密码 创建邮件列表 并发送电子邮件...
  • 超级公式栏 (轻松编辑多行文本和公式); 阅读版式 (轻松读取和编辑大量单元格); 粘贴到过滤范围...
  • 合并单元格/行/列 不会丢失数据; 拆分单元格内容; 合并重复的行/列...防止细胞重复; 比较范围...
  • 选择重复或唯一 行; 选择空白行 (所有单元格都是空的); 超级查找和模糊查找 在许多工作簿中; 随机选择...
  • 确切的副本 多个单元格,无需更改公式参考; 自动创建参考 到多张纸; 插入项目符号,复选框等...
  • 提取文字,添加文本,按位置删除, 删除空间; 创建和打印分页小计; 在单元格内容和注释之间转换...
  • 超级滤镜 (将过滤方案保存并应用于其他工作表); 高级排序 按月/周/日,频率及更多; 特殊过滤器 用粗体,斜体...
  • 结合工作簿和工作表; 根据关键列合并表; 将数据分割成多个工作表; 批量转换xls,xlsx和PDF...
  • 超过300种强大功能。 支持Office / Excel 2007-2019和365。支持所有语言。 在您的企业或组织中轻松部署。 完整功能30天免费试用。 60天退款保证。
kte选项卡201905

Office选项卡为Office带来了选项卡式界面,使您的工作更加轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!
officetab底部
Say something here...
symbols left.
You are guest
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Pradeep · 1 years ago
    Hi, How to do this for Colms to rows. Thank you
    • To post as a guest, your comment is unpublished.
      Jan steihn · 11 months ago
      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, ...
  • To post as a guest, your comment is unpublished.
    Maha · 1 years ago
    Thanks alot _/\_ Awesome job with =INDEX($A:$A,ROW(B1)*5-5+COLUMN(B1))
    worked perfectly
  • To post as a guest, your comment is unpublished.
    Arun Balaji VN · 1 years ago
    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
  • To post as a guest, your comment is unpublished.
    Sian · 2 years ago
    This is fricking AWESOME!!! Thank you SO much. Your example was exactly what I needed and it worked beautifully.
  • To post as a guest, your comment is unpublished.
    hamidreza · 3 years ago
    =INDEX($A:$A,ROW(A1)*5-5+COLUMN(A1))
    It was very simple and really useful. Thank you so much
  • To post as a guest, your comment is unpublished.
    Thank · 3 years ago
    It was great! Thank you! You saved me hours of manual work!
  • To post as a guest, your comment is unpublished.
    xplode · 3 years ago
    Thank you so much!
    It was really helpful. :)
  • To post as a guest, your comment is unpublished.
    MTVN · 4 years ago
    What formula to transpose every 5 rows to a single column?
  • To post as a guest, your comment is unpublished.
    hgimongu · 4 years ago
    Hi!

    May I ask you how to add Blank cell delimits records, instead of 5 as the data I am handling hasn't got fix number of rows. I believe the part which I should change may be around this part of the code:

    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

    Best
    • To post as a guest, your comment is unpublished.
      Mark.lewis2020 · 11 months ago
      I have the same issue , where the columns are not fixed, and there are empty lines, but I have a same character and end of each data set , that is "=" can I use this as delimiter , that breaks the loop, and next line is considered as new data set ?
    • To post as a guest, your comment is unpublished.
      Mark · 11 months ago
      did you get an answer for the same as i have the same issue , columns are not fixed in numbers, what should I do , can I use a particular character as a delimiter that breaks the loop and count next line and new data set ?