How to insert row automatically after certain number?

G

ghost

Hi,

I have a list that start from 1 to 2851 row, what I want to do is inserting
a blank row after 77 items. Each 77 items should be separated by row.

Thansk
 
J

JLatham

Something like this should get you going:

Sub InsertNewRows()
Const firstRow = 1 ' change if needed
Const groupSize = 77 ' change if desired
'identify a column where there is
'something in a cell in it in the
'last used row on the sheet
Const baseColumn = "A"
Dim lastRow As Long

'for improved performance
Application.ScreenUpdating = False
'choose starting point
Range(baseColumn & groupSize + firstRow).Select
'initialize lastRow value
lastRow = Range(baseColumn & Rows.Count).End(xlUp).Row
'do the work
Do Until ActiveCell.Row > lastRow
ActiveCell.EntireRow.Insert ' new row
ActiveCell.Offset(groupSize + 1, 0).Activate
'redefine last row
lastRow = Range(baseColumn & Rows.Count).End(xlUp).Row
Loop
End Sub

To put the code into your workbook press [Alt]+[F11] to open the VB Editor.
In there choose Insert | Module and copy and paste the code above into it.
Make any changes to baseColumn and firstRow that need to be made. Close the
VB Editor, choose the sheet with data on it and use Tools | Macro | Macros to
select the macro and [Run] it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top