跳到主要內容

如何將每5或n行從一列轉置為多列?

doc每5行轉置1

假設您在A列中有較長的數據,現在,您想將A列中的每5行轉置為多列,例如將A1:A5轉換為C6:G6,將A6:A10轉換為C7:G7,依此類推顯示以下截圖。 如果不在Excel中重複複製和粘貼,如何處理此任務?

使用公式將每5或n行從一列轉置為多列

使用VBA代碼將每5或n行從一列轉置為多列

將每 5 行或 n 行從一列轉置為多列 Kutools for Excel


在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。 在列中選擇數據,然後單擊 庫工具 > 範圍 > 變換範圍,請參見屏幕截圖:

2。 在 變換範圍 對話框中選擇 單列到範圍 選項下 轉換類型,然後檢查 固定值每條記錄行,然後在中指定要轉置到的列數 固定值 框,請參見屏幕截圖:

doc每5行轉置8

3。 然後點擊 Ok 按鈕,在彈出的框中,請選擇一個單元格以輸出結果,請參見屏幕截圖:

doc每5行轉置9

4。 然後點擊 OK 按鈕,並且您的列數據已每5行轉置一次,如下所示的屏幕截圖:

doc每5行轉置6

下載並免費試用 Kutools for Excel 現在 !


Kutools for Excel:具有300多個方便的Excel加載項,可以在30天內免費試用,沒有任何限制。 立即下載並免費試用!

最佳辦公生產力工具

熱門特色: 尋找、突出顯示或識別重複項   |  刪除空白行   |  合併列或儲存格而不遺失數據   |   沒有公式的回合 ...
超級查詢: 多條件VLookup    多值VLookup  |   跨多個工作表的 VLookup   |   模糊查詢 ....
高級下拉列表: 快速建立下拉列表   |  依賴下拉列表   |  多選下拉列表 ....
欄目經理: 新增特定數量的列  |  移動列  |  切換隱藏列的可見性狀態  |  比較範圍和列 ...
特色功能: 網格焦點   |  設計圖   |   大方程式酒吧    工作簿和工作表管理器   |  資源庫 (自動文字)   |  日期選擇器   |  合併工作表   |  加密/解密單元格    按清單發送電子郵件   |  超級濾鏡   |   特殊過濾器 (過濾粗體/斜體/刪除線...)...
前 15 個工具集12 文本 工具 (添加文本, 刪除字符,...)   |   50+ 圖表 類型 (甘特圖,...)   |   40+ 實用 公式 (根據生日計算年齡,...)   |   19 插入 工具 (插入二維碼, 從路徑插入圖片,...)   |   12 轉化 工具 (數字到單詞, 貨幣兌換,...)   |   7 合併與拆分 工具 (高級合併行, 分裂細胞,...)   |   ... 和更多

增強您的 Excel 技能 Kutools for Excel,體驗前所未有的效率。 Kutools for Excel 提供 300 多種高級功能,可提高工作效率並節省時間。  點擊此處獲取您最需要的功能...

kte選項卡201905


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