Insert variable number of rows for every row in spreadsheet

Busybeaver

New Member
Joined
Nov 26, 2010
Messages
20
Afternoon and Happy New Year to all :)

Can someone please help me with a code for the below. What I'm trying to achieve is to insert rows below each line based on the number of lines required in the last column. I.e. No rows need to be inserted for the first 2 lines but 2 additional rows need to be inserted for the 3rd line.

I have tried so many codes that I have found online but can only find codes that will insert either only 1 row at a fixed range or will only insert rows once.

Unfortunately I don't have the knowledge to attempt to write a code like this by myself but would greatly appreciate any help from someone who does.

CRMTask OpenCategoryAddressSuburbDEL/REMBin typeBulk #PID #Total line Count
212226/2020
21-Dec-20​
*********DELFOOD0
211640/2020
21-Dec-20​
*********DELFOOD0
212343/2020
22-Dec-20​
*********DELFOOD32
211704/2020
21-Dec-20​
*********DELFOOD / GLASS1
206386/2020
21-Dec-20​
*********DELRUBBISH / RECYCLING / GLASS25
212350/2020
22-Dec-20​
*********DEL/REPAIRRUBBISH / FOOD1
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Try this:
VBA Code:
Sub Insert_Rows()
'Modified 12/31/2020  10:42:57 PM  EST
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Dim ans As Long
Lastrow = Cells(Rows.Count, "J").End(xlUp).Row

For i = Lastrow To 1 Step -1
    ans = Cells(i, "J").Value
        If ans > 0 Then Rows(i).Offset(1).Resize(ans).Insert
Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,094
Latest member
teemeren

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