VBA Code to Insert Rows Based on Cell Value and Copy Relevant Data

FrederiQ

New Member
Joined
Sep 23, 2015
Messages
11
Hi everybody,

A simple, yet impossible for me to figure out request. I found the below code that inserts rows based on the numeric value of the 8th column of a data set (with first row being headings) and also copies the data from the above rows in all inserted rows. However, I need a slight modification and I'm not able to figure out how to change the code. I need X-1 rows to be inserted instead of X. Would somebody provide me with the solution? Many thanks!

Sub RowsInsert()
Dim r As Long

For r = Range("A" & Rows.Count).End(xlUp).Row To 1 Step -1
With Cells(r, 8)
If IsNumeric(.Value) And Not IsEmpty(.Value) Then
Rows(r + 1).Resize(.Value).Insert
Range(Replace("A#:AC#", "#", r)).Copy Destination:=Range("A" & r + 1).Resize(.Value)
End If
End With
Next r
End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top