Inserting 2 blank rows after each line in selection

PATSYS

Well-known Member
Joined
Mar 12, 2006
Messages
1,750
I have data in range D50:P100.

I want to insert 2 blanks rows after each of the lines in D50 to P100

How is this done in VBA?

Thanks
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Assuming the 50-100 rows are set (hedging based on your subject line that included the word Selection), this would place 2 rows below each row from 50-100.

Sub test()
Application.ScreenUpdating = False
Dim xRow&
For xRow = 100 To 50 Step -1
Rows(xRow + 1).Resize(2).Insert
Next xRow
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi Tom,

That worked well, thanks.

May I asked what if it is not a defined range i.e. I want it to insert 2 rows in SELECTION?

Thanks again
 
Upvote 0
I would do it this way:

Code:
Sub InsertSelectedRows()
Application.ScreenUpdating = False
Dim FirstRow&, LastRow&, xRow&
With Selection
FirstRow = .Row
LastRow = .Rows.Count + .Row - 1
End With
For xRow = LastRow To FirstRow Step -1
Rows(xRow + 1).Resize(2).Insert
Next xRow
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,763
Members
452,940
Latest member
rootytrip

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