ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   make excel copy a row and automatically insert new rows (https://www.excelbanter.com/excel-discussion-misc-queries/239543-make-excel-copy-row-automatically-insert-new-rows.html)

robin

make excel copy a row and automatically insert new rows
 
How do I make excel copy a row and then automatically insert new rows that
are copies of that row based on a number input by a user (i.e. a user unoyuts
'10' in a cell excel copies the content of row 51 abd then inserts 10 new
rows that are copies of row 51)?

Don Guillett

make excel copy a row and automatically insert new rows
 
Sub copyrows()
numrows = InputBox("Number of rows")
'Rows(ActiveCell.Row).Copy ActiveCell.Resize(numrows)
Rows(ActiveCell.Row).Copy
ActiveCell.Resize(numrows).Insert
Application.CutCopyMode = False
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Robin" wrote in message
...
How do I make excel copy a row and then automatically insert new rows that
are copies of that row based on a number input by a user (i.e. a user
unoyuts
'10' in a cell excel copies the content of row 51 abd then inserts 10 new
rows that are copies of row 51)?



robin

make excel copy a row and automatically insert new rows
 
Don,
Thank you for your help.
Was able to get your code to work (copy and insert rows in Excel). It
worked good. I do have a follow-on question. Is there a way to get one of
the copied cells to increment based on a starting number in the row to be
copied? In other words, in the row to be copied there is a cell with a value
of '1' and we need that value to be incremented for each new row that is
inserted. So, if we have Excel insert ten additional rows, that number
should be incremented from '1' in the copied row all the way to '11' in the
newly inserted rows.
Sincerely,

Robin

Does that make sense?


"Don Guillett" wrote:

Sub copyrows()
numrows = InputBox("Number of rows")
'Rows(ActiveCell.Row).Copy ActiveCell.Resize(numrows)
Rows(ActiveCell.Row).Copy
ActiveCell.Resize(numrows).Insert
Application.CutCopyMode = False
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Robin" wrote in message
...
How do I make excel copy a row and then automatically insert new rows that
are copies of that row based on a number input by a user (i.e. a user
unoyuts
'10' in a cell excel copies the content of row 51 abd then inserts 10 new
rows that are copies of row 51)?





All times are GMT +1. The time now is 12:54 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com