After Every Tenth Row Insert 2 Blank Rows without any Format

ameenuksg

Board Regular
Joined
Jul 11, 2017
Messages
83
Hi I have recorded the following Macro but it seems to insert another extra row(third row) with format which I did not intend to record:

Sub Macro5()
'
' Macro5 Macro
'

'
ActiveCell.Range("A1:A10").Select
ActiveWindow.SmallScroll Down:=3
ActiveCell.Offset(10, 0).Rows("1:1").EntireRow.Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlDown
Selection.ClearFormats
ActiveCell.Offset(1, 0).Rows("1:1").EntireRow.Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
ActiveWindow.SmallScroll Down:=3
ActiveCell.Offset(1, 0).Range("A1").Select
End Sub


Anyone able to help me correct the above macro to insert 2 blank rows only after the 10th row without any format and then select the next row after the 2 blank rows ?
 
Do you have more than 15 rows of data?
 
Upvote 0

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Nope...last couple of rows were only 11 rows of data and it still inserted blank rows after the 10th row
 
Last edited:
Upvote 0
You said you wanted it not to insert blanks if there were only 15 rows to begin with.
Which is what it does.
 
Upvote 0
Is this what you want
Code:
Sub Insertrws()
   Dim lr As Long, i As Long, j As Long
   lr = Range("A" & Rows.Count).End(xlUp).row
   j = ((Int(lr / 10) * 10) + 1)
   For i = IIf(lr - j < 15, j - 10, j) To 11 Step -10
      Rows(i + 1).Resize(2).Insert
      Rows(i + 1).Resize(2).Clear
   Next i
End Sub
 
Upvote 0
What a beauty! this is exactly what I wanted..thank you so much!

Is this what you want
Code:
Sub Insertrws()
   Dim lr As Long, i As Long, j As Long
   lr = Range("A" & Rows.Count).End(xlUp).row
   j = ((Int(lr / 10) * 10) + 1)
   For i = IIf(lr - j < 15, j - 10, j) To 11 Step -10
      Rows(i + 1).Resize(2).Insert
      Rows(i + 1).Resize(2).Clear
   Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,091
Messages
6,128,775
Members
449,468
Latest member
AGreen17

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