Hello!
I have an issue where I'm trying to add rows based on a cell value in column 2, and then copy that row's contents to those new rows. I found the VBA code below on another thread, but I have not been able to figure out one small issue.
The cell value in column 2 should be the TOTAL number of rows, but because the code doesn't account for the original row, there is one too many for each iteration.
For example, Business ABC should have 10 copies, and thus, has entered a 10 in column 2. I will run the code and it will ADD 10 rows below the original row. Now there are 11 rows of data for Business ABC.
Thanks in advance!
I have an issue where I'm trying to add rows based on a cell value in column 2, and then copy that row's contents to those new rows. I found the VBA code below on another thread, but I have not been able to figure out one small issue.
The cell value in column 2 should be the TOTAL number of rows, but because the code doesn't account for the original row, there is one too many for each iteration.
For example, Business ABC should have 10 copies, and thus, has entered a 10 in column 2. I will run the code and it will ADD 10 rows below the original row. Now there are 11 rows of data for Business ABC.
Thanks in advance!
VBA Code:
Sub Inert_rows()
Dim r As Long
For r = Range("A" & Rows.Count).End(xlUp).Row To 1 Step -1
With Cells(r, 2)
If IsNumeric(.Value) And Not IsEmpty(.Value) Then
Rows(r + 1).Resize(.Value).Insert
Range(Replace("A#:H#", "#", r)).Copy Destination:=Range("A" & r + 1).Resize(.Value)
End If
End With
Next r
End Sub