VBA code to navigate and insert rows

lishman

New Member
Joined
Jun 24, 2005
Messages
17
Please can you help, I need to modify a spreadsheet which has 40,000 lines. Is there VBA code which will allow me to move down 22 rows, insert 3 rows, then move cell reference to the next cell after the 3 rows have been inserted, then repeat by moving down 22 rows then inserting 3 rows etc etc
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Simplified below by showing each row with an x. after every 3rd row of X's I have 2 blank rows.

x
x
x


x
x
x
inserted 2 rows here

x
x
x
inserted 2 rows here

x
x
x would like to add code to automatically insert 2 rows after this row
x
x
x would like to add code to automatically insert 2 rows after this row
x
x
x
x
x
 
Upvote 0
Code:
Sub insertRows()

Range("A1").Select
Do While ActiveCell.Row < Range("A" & Rows.Count).End(xlUp).Row
    ActiveCell.Offset(3, 0).Select
    Rows(ActiveCell.Row & ":" & ActiveCell.Row + 1).Select
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    ActiveCell.Offset(2, 0).Select
Loop
End Sub


Try this

Above code assume you have no rows inserted manually before running this code.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

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