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 for Applications 窗口。

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 > 範圍 > 變換範圍,請參見屏幕截圖:

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 ?