Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to insert new rows in excel using vba 3

Status
Not open for further replies.

StormVoogd

Programmer
Apr 19, 2001
10
NL
hai

i would like to know how to insert new rows in excel or how to move for example row 2 to row 3 so row 2 is free again...

i'm using vba so there has to be an solution to my problem,

hope someone knows the answer....

Grtz....X-)
 
The best way to find out how to do this is to record a macro.

Press record then move or insert rows.
then hit stop.

you can then go into VB Editor, look at the code it has just created in Module1. This will show you how to do it.

It will give you something like this:

Rows("2:2").Select
Selection.Insert Shift:=xlDown

to get this to work in your sub you will need to add activesheet to the first line:

ActiveSheet.Rows("2:2").Select
Selection.Insert Shift:=xlDown

You could also replace the 2 with a variable like:

Dim x as integer
x = 2
Activesheet.Rows(x & ":" & x).Select
Selection.Insert Shift:=xlDown


Hope this helps.
 

DarkSun
:

Now let's not forget to tell StormVoogd about eliminating unneeded code. All of the wonderful examples above may be shortened to:

Rows("2:2").Insert Shift:=xlDown

ActiveSheet.Rows("2:2").Insert Shift:=xlDown

Dim x As Integer
x = 2
ActiveSheet.Rows(x & ":" & x).Insert Shift:=xlDown

Excel VBA Macro Recording is a great learning tool; however it doesn't always provide the shortest method to perform a given task. Regards,

LoNeRaVeR
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top