Insert Multiple Rows

Edman

New Member
Joined
Nov 18, 2008
Messages
42
Hi all,

I need to make the following code insert more than one row. How can I modify the code to insert 2 or 3 or 4, etc rows?

FinalRow = Cells(Rows.Count, 3).End(xlUp).Row
For x = FinalRow To 5 Step -1
If Cells(x, "A").Value <> Cells(x + 1, "A").Value Then Rows(x + 1).Insert
Next x

Thanks in advance for your help
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Edman,

Sample raw data:


Excel 2007
ABC
5555
6666
7777
8888
9999
101010
11
Sheet1


After the macro for inserting 2 rows:


Excel 2007
ABC
5555
6
7
8666
9
10
11777
12
13
14888
15
16
17999
18
19
201010
21
Sheet1




See the 2 in the code:


Rich (BB code):
Option Explicit
Sub Test()

Dim FinalRow As Long, x As Long

FinalRow = Cells(Rows.Count, 3).End(xlUp).Row
For x = FinalRow To 5 Step -1
  If Cells(x, "A").Value <> Cells(x + 1, "A").Value Then Rows(x + 1).Resize(2).Insert
Next x

End Sub
 
Upvote 0

Forum statistics

Threads
1,203,241
Messages
6,054,321
Members
444,717
Latest member
melindanegron

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