Insert multiple lines with a macro
DADY07
Posted messages
8
Status
Member
-
Thorgal28 -
Thorgal28 -
Hello, could someone help me!
I would like to insert 10 rows at once using a macro
this macro inserts a single row but how can I make it understand that I need 10 without having to run this macro 10 times
Rows("5:5").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Thank you in advanceConfiguration: Windows XP
Internet Explorer 7.0
I would like to insert 10 rows at once using a macro
this macro inserts a single row but how can I make it understand that I need 10 without having to run this macro 10 times
Rows("5:5").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Thank you in advanceConfiguration: Windows XP
Internet Explorer 7.0
2 answers
-
Good evening,
By pointing to the beach, and the .select is unnecessary:
Rows("5:14").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
or even shorter if it's the default values:
Rows("5:14").Insert
eric-
-
Hello Anksuamon,
I confirm that Eriic's "simple" solution works well.
Sub insertion_10_lignes()
'Inserting 10 rows starting from row 5
Rows("5:15").Insert 'Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
MsgBox "Insertion of 10 rows completed!", vbInformation
End Sub
Note:
Please be careful not to keep your data in "Table" format in Excel (I had this problem at first!).
If that's the case, convert your data back to normal format: Excel Menu>Design>Convert to Range
Then re-run the macro "insertion_10_lignes".
-