Excel VBA macro to add a new row every 20th row from A2 not A1

Iheartexcl

New Member
Joined
Jun 18, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
have a code that misses row A1 and then adds 20 rows after this. I need the code to add 20 rows after A2

Sub AddRows()
ScreenUpdating = False
With ActiveSheet
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

End With
Dim AddRows As Integer: AddRows = 20
Dim i As Integer: i = lastRow
Do While i <> 1
Rows(i & ":" & i + AddRows - 1).Insert
i = i - 1
Loop
ScreenUpdating = True
End Sub
 

Attachments

  • original.jpg
    original.jpg
    108.3 KB · Views: 5
  • macro results.jpg
    macro results.jpg
    27.5 KB · Views: 5
  • outcome wanted.jpg
    outcome wanted.jpg
    121.7 KB · Views: 5

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: I need a macro that starts at A2 and for every 20 rows, select columns D-W
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
Change
Rich (BB code):
Do While i <> 1

To
Rich (BB code):
Do While i <> 2
 
Upvote 0

Forum statistics

Threads
1,224,298
Messages
6,177,750
Members
452,798
Latest member
mlance617

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