Skip to main content

How to repeat rows a specified number of times based on another column in Excel?

Have you ever tried to repeat a row based on another column value as below screenshot shown? In this article, I will introduce the method on solving this job in Excel.
doc repeat rows based on column 1

Repeat rows based on another column value with VBA

Repeat rows based on another column value by Kutools for Excel

Repeat rows with a fixed time by Kutools for Excel


Repeat rows based on another column value with VBA

Here I have a code which can quickly repeat the rows based on the last column values.

1. Press Alt + F11 keys to enable Microsoft Visual Basic for Applications window.

2. Click Insert > Module, then copy below code and paste it to the new Module script.

VBA: Repeat rows based on another column value

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 repeat rows based on column 2

3. Press F5 key, a dialog pops out, select the number list which the rows will be repeated based on.
doc repeat rows based on column 3

4. Click OK, the rows have been repeated based on the selected column value.
doc repeat rows based on column 1


Repeat rows based on another column value by Kutools for Excel

If you are not good at using VBA, you can try Kutools for Excel’s Duplicate Rows/Columns Based on Cell Value feature, which just needs two steps.

Kutools for Excel, with more than 300 handy functions, makes your jobs more easier. 

1. Click Kutools > Insert > Duplicate Rows/Columns Based on Cell Value.
doc repeat rows fixed time 1

2. In the popping dialog, choose Copy and insert rows option in the Type section, then choose the range that you want to repeat to Insert Range textbox, and choose the column that decides the repeat times to the Repeat Times textbox. Click Ok.
doc repeat rows fixed time 1

Then the rows will be repeated by the selected column.
doc repeat rows fixed time 1


Repeat rows with a fixed time by Kutools for Excel

If you want to repeat rows with a fixed time without inserting rows one by one, you can try to use the Insert Blank Rows & Columns and Fill Blank Cells utilities of Kutools for Excel to quickly handle this job.
doc repeat rows fixed time 1

After installing Kutools for Excel, please do as below:(Free Download Kutools for Excel Now!)

1. Select the data range you want to repeat rows, click Kutools > Insert > Insert Blank Rows & Columns. Then in the Insert Blank Rows & Columns dialog, check Blank rows option, then type 1 into Interval of textbox, and type the number you want to repeat rows in Rows textbox.
doc repeat rows fixed time 2

2. Click Ok, the blank rows have been inserted below each row.
doc repeat rows fixed time 3

3. Keep the range selected, click Kutools > Insert > Fill Blank Cells. In the Fill Blank Cells dialog, check Based on values and Down options.
doc repeat rows fixed time 4

4. Click Ok. Now the blank cells have been filled with above value.
doc repeat rows fixed time 5

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...

Description


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
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