Insert a specific number of rows

F

Faraz A. Qureshi

What would be the correct syntax of inserting a specific number of rows below
the active cell? For instance 4 or 5 rows?
 
O

OssieMac

Hi Faraz,

Try the following. Note that a space and underscore at the end of a line is
a line break in an otherwise single line of code.

Range(ActiveCell.Offset(1, 0), _
ActiveCell.Offset(5, 0)) _
.EntireRow.Insert
 
R

Rick Rothstein

This is a little more direct..

ActiveCell.Offset(1).Resize(4).EntireRow.Insert

You seem hesitant about using Offset for some reason, although I'm not sure
why. You can do it without using Offset like this...

Cells(ActiveCell.Row + 1, 1).Resize(4).EntireRow.Insert

but, quite frankly, I would just use the first method and be done with it.
 
F

Faraz A. Qureshi

Thanx Rick!
It's not actually that I am hesitant. I just was eager 2 know if there could
be direct way for the purpose of knowledge.
 
R

Rick Rothstein

See, this is what happens when you post a message at 3:00 am in the morning
(local time), you get sloppy. That last example I posted works, but using
Cells is not the way I should have done it, rather, I should have used Rows
directly...

Rows(ActiveCell.Row + 1).Resize(4).Insert

Because this uses one less function call than either of my prior examples,
this would be my preference for use in actual code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top