need a macro

JasonLeVan

Board Regular
Joined
Feb 7, 2011
Messages
121
I am looking for a macro that will start in row 3 and and count down 5 rows and insert a blank row, then after that new blank row count 5 more rows and insert another blank space, and repeat through the whole worksheet
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Try:
Rich (BB code):
Dim InsertRows ()
Dim i as Long, LR as Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 8 to LR Step 5
 Rows(i).Insert
 i = i + 1
Next i
End Sub
Change the number 8 if it inserts rows in the wrong place - it's not clear if you mean count down 5 rows from row 3 or including row 3
 
Upvote 0
this works great except once it gets to the end of it, it skips like the last 15 lines and leaves them all together, but the other 8-12 groups it makes great, any idea for a fix

QUOTE=JackDanIce;2638533]Try:
Rich (BB code):
Dim InsertRows ()
Dim i as Long, LR as Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 8 to LR Step 5
 Rows(i).Insert
 i = i + 1
Next i
End Sub
Change the number 8 if it inserts rows in the wrong place - it's not clear if you mean count down 5 rows from row 3 or including row 3[/QUOTE]
 
Upvote 0
Without knowing how your spreadsheet/data is laid out, I can't tell what's going wrong - macro should work based on the original description you gave.
 
Upvote 0
I think it should be

Rich (BB code):
Sub InsertRows()
Dim i As Long, LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 8 To LR Step 5
 Rows(i).Insert
 i = i - 1
Next i
End Sub
 
Upvote 0
<TABLE style="WIDTH: 444px; BORDER-COLLAPSE: collapse; HEIGHT: 95px" border=0 cellSpacing=0 cellPadding=0 width=444><COLGROUP><COL style="WIDTH: 64pt; mso-width-source: userset; mso-width-alt: 3015" width=85><COL style="WIDTH: 50pt; mso-width-source: userset; mso-width-alt: 2360" width=66><COL style="WIDTH: 130pt; mso-width-source: userset; mso-width-alt: 6172" width=174><COL style="WIDTH: 67pt; mso-width-source: userset; mso-width-alt: 3157" width=89><TBODY><TR style="HEIGHT: 14.4pt" height=19><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; WIDTH: 64pt; HEIGHT: 14.4pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl63 height=19 width=85>3172186</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; WIDTH: 50pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" width=66 align=right>2.49</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; WIDTH: 130pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" width=174>SWITCH QT 3WAY 15A </TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; WIDTH: 67pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" width=89>003</TD></TR><TR style="HEIGHT: 14.4pt" height=19><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; HEIGHT: 14.4pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl63 height=19>3172186</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" align=right>2.49 </TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0">SWITCH QT 3WAY 15A </TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0">003</TD></TR><TR style="HEIGHT: 14.4pt" height=19><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; HEIGHT: 14.4pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl63 height=19>3172186</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" align=right>2.49 </TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0">SWITCH QT 3WAY 15A </TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0">003</TD></TR><TR style="HEIGHT: 14.4pt" height=19><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; HEIGHT: 14.4pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl63 height=19>3172186</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" align=right>2.49 </TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0">SWITCH QT 3WAY 15A </TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0">003</TD></TR><TR style="HEIGHT: 14.4pt" height=19><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; HEIGHT: 14.4pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl63 height=19>3172186</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" align=right>2.49 </TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0">SWITCH QT 3WAY 15A </TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0">003


</TD></TR></TBODY></TABLE>


here is a example for data that goes in column a ,b ,c and d starting in row 3. if you fill down the data say 300 rows and run the macro possibly you may be what it is doing.
 
Upvote 0
Try this then:
Code:
Sub InsertRows()
Application.ScreenUpdating = False
Dim i As Long
i = 8
Do While Not IsEmpty(Range("A" & i))
 Rows(i).Insert
 i = i + 6
Loop
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,844
Members
452,948
Latest member
UsmanAli786

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