PDA

View Full Version : Solved: Insert lines after so many rows



sassora
03-20-2008, 01:05 AM
How do you insert lines after every: i) 1 line, ii) 2 lines using the mod function?

I have data in Excel say from 1 to 1000. I wanted to use the mod function because it should be easy to change the base to change the number of lines in between the insert.

If the is an easier way that is easily editable then great

JimmyTheHand
03-20-2008, 01:11 AM
You mean, new rows into a table?
Or new lines into a text file?
Are you sure you want to do it using the mod operator? There might be simpler solutions.

mdmackillop
03-20-2008, 01:14 AM
Something like

Sub InsertRows()
Dim i As Long, Space As Long
Space = InputBox("What grouping?")
For i = Cells(Rows.Count, 1).End(xlUp).Row To 1 Step -1
If i Mod Space = 0 Then
Cells(i, 1).EntireRow.Insert
End If
Next
End Sub

sassora
03-20-2008, 01:19 AM
Yes exactly like that! Thanks

mdmackillop
03-20-2008, 05:26 AM
Hi Sassora,
If this is Solved, you can mark it so using the Thread Tools dropdown.
Regards
MD