VBA error insert variable number of Rows

SBF12345

Well-known Member
Joined
Jul 26, 2014
Messages
614
I am having trouble with the following line:

Code:
COM.Worksheets(g).Rows(2:B).Insert Shift:= xlDown

I wrote the code in the text editor and copied it to a module so I'm not totally sure what is wrong with it. My goal is to be able to insert a variable number of rows (B is number of rows to insert variable) starting at row 2 and shifting the rows down.

What might be the best way to insert B number of rows at row 2?

Thanks!
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Try using

Code:
Rows(2:" & B & ")
 
Upvote 0
If B is the number of rows to insert, you could use this.

Code:
COM.Worksheets(g).Rows(2).Resize(B, 1).EntireRow.Insert Shift:= xlDown
 
Upvote 0

Forum statistics

Threads
1,215,225
Messages
6,123,732
Members
449,116
Latest member
Aaagu

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