# Solved: Macro to insert a row



## Akuller (Feb 12, 2004)

Hi, I'm trying to build a simple macro in Excel to do the following:

After I insert data in column "U", I want a new blank row to be inserted directly below the row I'm in, and then bring me to the column "O" in that newly created row. 

I created the following and it did not work: it inserts the row above instead of below. I'm very new to macros..can you tell?

Rows("3:3").Select
Range("E3").Activate
Selection.Insert Shift:=xlDown
Range("O4").Select
End Sub

Thanks,


----------



## slurpee55 (Oct 20, 2004)

You are selecting Row 3 ("Rows("3:3").Select") and then this line 
"Selection.Insert Shift:=xlDown" 
shifts your selection (Row 3, that is) down.
Change it to
"Selection.Insert Shift:=xlUp" and things should work correctly.


----------



## Akuller (Feb 12, 2004)

Thx-I'll let you know..


----------



## Akuller (Feb 12, 2004)

Yep, that was it! Thanks so much!!!


----------



## Akuller (Feb 12, 2004)

Ok, it worked the first time, then when I went to row U in the newly created row, entered data, then ran the macro again, It inserted a row above my data. macro reads:

Rows("3:3").Select
Range("E3").Activate
Selection.Insert Shift:=xlUp
Range("O4").Select
End Sub


----------



## slurpee55 (Oct 20, 2004)

The way it is written, it will always select Row 3. When you select 3 and insert a row above it, what was row 3 becomes row 4 and the new row is row 3. So when you entered data into the row you had just entered, you entered data into row 3, and running the macro again caused the new data to be moved down.
If you prefer, replace
Rows("3:3").Select
with something like
ActiveCell.Select
Then whatever cell you have your cursor in will be the row chosen to have a new row inserted above it.


----------



## Akuller (Feb 12, 2004)

Hi, I'm clearly VBA challenged...this is what I put in and got run time error on the Slection.Insert shift:=xlup


ActiveCell.Select
Range("E3").Activate
Selection.Insert Shift:=xlUp
Range("O4").Select
End Sub


----------



## slurpee55 (Oct 20, 2004)

Put this in a module and it works for me

```
Sub InsertRow()
Rows("3:3").Select
Range("E3").Activate
Selection.Insert Shift:=xlUp
Range("O3").Select
End Sub
```


----------



## slurpee55 (Oct 20, 2004)

Here is my test file


----------



## Akuller (Feb 12, 2004)

Got it!! Thanks so much....


----------

