Virtual Row Selection

B

Bishop

I'm in a With statement and I'm trying to select one more rows depending on
the value of my variables. For example, say
Checkrow = 4
AddRow = 2
I want to insert 2 rows below row 4 this is what I'm trying:
..Rows((CheckRow + 1):(CheckRow + 1 + AddRow - 1)).Select
Selection.Insert Shift:=xlDown
This would be the same as:
Rows("3:4").Select
Selection.Insert Shift:=xlDown
but I'm getting a compile error: expected list separator or )

How do I make this work?
 
R

Rick Rothstein

I'm pretty sure this will do what you want...

Checkrow = 4
AddRow = 2
Rows(CheckRow + 1).Resize(AddRow).Insert Shift:=xlShiftDown
 
B

Bishop

VBE didn't recognize Shift:=xlShiftDown but I read the helpfile and this
worked:
Rows(CheckRow + 1).Resize(AddRow).Insert(xlShiftDown)

But this is perfect! Exactly what I needed. Thanks.
 
R

Rick Rothstein

Odd, the line of code that I posted worked fine (I tested it before I posted
it)... did you copy it exactly as I wrote it? Your version also works on my
system, so you might as well use it. I'd be curious at to why what I posted
originally didn't work for you.
 

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