跳到主要內容

如何根據Excel中的另一列將行重複指定的次數?

您是否曾經嘗試過根據另一個列值重複行,如下面的屏幕截圖所示? 在本文中,我將介紹在Excel中解決此工作的方法。
doc根據第1列重複行

使用VBA根據另一個列值重複行

Kutools for Excel 根據另一個列值重複行

通過Kutools for Excel在固定的時間重複行


使用VBA根據另一個列值重複行

在這裡,我有一個代碼,可以根據最後一列的值快速重複行。

1。 按 Alt + F11鍵 啟用鍵 Microsoft Visual Basic for Applications 窗口。

2。 點擊 插入 > 模塊,然後復制下面的代碼並將其粘貼到新代碼中 模塊 腳本。

VBA:根據另一個列值重複行

Sub CopyRow()
'UpdatebyExtendoffice20181011
Dim xRg As Range
Dim xCRg As Range
Dim xFNum As Integer
Dim xRN As Integer
On Error Resume Next
SelectRange:
xTxt = ActiveWindow.RangeSelection.Address
Set xRg = Application.InputBox("Select the number value", "Kutools for Excel", xTxt, , , , , 8)
If xRg Is Nothing Then Exit Sub

If xRg.Columns.Count > 1 Then
    MsgBox "Please select single column!"
    GoTo SelectRange
End If
Application.ScreenUpdating = False
For xFNum = xRg.Count To 1 Step -1
Set xCRg = xRg.Item(xFNum)
    xRN = CInt(xCRg.Value)
    With Rows(xCRg.Row)
    .Copy
    .Resize(xRN).Insert
    End With
Next
Application.ScreenUpdating = True
End Sub

doc根據第2列重複行

3。 按 F5 鍵,將彈出一個對話框,選擇要基於其重複行的數字列表。
doc根據第3列重複行

4.單擊“確定”,已根據選定的列值重複行。
doc根據第1列重複行


Kutools for Excel 根據另一個列值重複行

如果你不擅長使用VBA,你可以試試 Excel的Kutools基於單元格值的重複行/列 功能,只需要兩個步驟。

Excel的Kutools, 與以上 300 方便的功能,使您的工作更加輕鬆。 

1。 點擊 庫工具 > 插入 > 基於單元格值的重複行/列.
doc重複行固定時間1

2.在彈出的對話框中,選擇 複製並插入行 在選項 類別 部分,然後選擇要重複的範圍 插入範圍e 文本框,然後選擇決定重複次數的列 重複次數 文本框。 請點擊 Ok.
doc重複行固定時間1

然後行將被選定的列重複。
doc重複行固定時間1


通過Kutools for Excel在固定的時間重複行

如果您想以固定的時間重複行而又不逐行插入行,則可以嘗試使用 插入空白行和列 填寫空白單元格 的效用 Excel的Kutools 快速處理這項工作。
doc重複行固定時間1

安裝後 Kutools for Excel,請執行以下操作:(立即免費下載Kutools for Excel!)

1.選擇要重複行的數據范圍,單擊 庫工具 > 插入 > 插入空白行和列。 然後在 插入空白行和列 對話框,檢查 空白行 選項,然後輸入 1 加到 間隔of文本框,然後鍵入要在其中重複行的數字 文本框。
doc重複行固定時間2

2。 點擊 Ok,空白行已插入到每行下方。
doc重複行固定時間3

3.保持選中範圍,然後單擊 庫工具 > 插入 > 填寫空白單元格。 在 填寫空白單元格 對話框,檢查 基於價值 選項。
doc重複行固定時間4

4。 點擊 Ok。 現在,空白單元格已填充上述值。
doc重複行固定時間5

最佳辦公生產力工具

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

使用 Kutools for Excel 增強您的 Excel 技能,體驗前所未有的效率。 Kutools for Excel 提供了 300 多種進階功能來提高生產力並節省時間。  點擊此處獲取您最需要的功能...

產品描述


Office選項卡為Office帶來了選項卡式界面,使您的工作更加輕鬆

  • 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,發布者,Access,Visio和Project。
  • 在同一窗口的新選項卡中而不是在新窗口中打開並創建多個文檔。
  • 將您的工作效率提高 50%,每天為您減少數百次鼠標點擊!
Comments (5)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Update on my previous comment. It looks like it's not happening everytime but I can't see why some rows are working as expected and others aren't.
This comment was minimized by the moderator on the site
Hi, Megan Brennan, could you show me what rows the feature won't work at?
This comment was minimized by the moderator on the site
Hi there,

I've just tried the Repeat rows based on another column value by Kutools for Excel functionality and it seems to be squaring the (repeat value + 1).

For example if I have a repeat value for a row as 2, then it repeats that row another 8 times to make a total of 9 rows of the same data.
If I have a repeat value of 4, then it repeats that row for another 24 times to make a total of 25 rows of the same data.

So repeat value of 1 -> Total 4 rows -> Should be total of 2
2 -> Total 9 rows -> Should be total of 3
3 -> Total 16 rows -> Should be total of 4
4 -> Total 25 rows -> Should be total of 5
7 -> Total 64 rows -> Should be total of 8
This comment was minimized by the moderator on the site
Hi, how to move the repeated output to the side of the original data?
This comment was minimized by the moderator on the site
Hi,yiyun zhu, you can make a copy of the original data, then use above method to handle the copy one, and keep the original data .
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations