Discussion Locked

Excel Template

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I am trying to create a macro that will run when a worksheet is opened and automatically insert a row every fourth row. The data is queried in a database and exported to Excel, and I need it separated. Some worksheets may only have 10 lines of data, but others may have 200. How do I tell it to do this? I am a newbie at VB, but that looks like the place to do it. Thanks for any help anyone can provide.

1 reply

by d_gilmour_1978

this code will insert a row every 4th row (you can change this by changing the mod 4 to mod 5 etc

Sub Macro1()
Sheets(1).Select
x = 1
While Cells(x, 1).Value <> ""
If x Mod 4 = 0 Then
Rows(x).Select
Selection.Insert Shift:=xlDown
End If
x = x + 1
Wend

End Sub

if you need any further assistance please repost via comments

This discussion is closed to new replies.