ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Automatically Increment numerically ordered (https://www.excelbanter.com/excel-discussion-misc-queries/240233-automatically-increment-numerically-ordered.html)

robin

Automatically Increment numerically ordered
 
Jim here is the code


Here is the code that copies and inserts the 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

Thanks!


Don Guillett

Automatically Increment numerically ordered
 
You start a new thread not bothering to refer to the original so it makes it
difficult to tell what you want. This looks like something I
provided...?????

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Robin" wrote in message
...
Jim here is the code


Here is the code that copies and inserts the 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

Thanks!



robin

Automatically Increment numerically ordered
 
I agree. Here is the original question.
Have code that automatically copies a row and then inserts new rows in a
worksheet that are copies of that row, based on a number entered by a user
through an InputBox. The first cell in the row contains a number that needs
to increment as the new rows are inserted. In other words, in the row that
is copied there is a cell with a value of '1' and I need that value to be
incremented for each new row that is inserted. So, if Excel inserts ten
additional rows, that number should be incremented from '1' in the copied row
all the way to '11' in the newly inserted rows.


Here is the code


Here is the code that copies and inserts the 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

Thanks!


Don Guillett

Automatically Increment numerically ordered
 
It also would have been nice to mention who authored the original code

Sub InsertRowsAndNumberFrom1()
ar = ActiveCell.Row
numrows = InputBox("Number of rows")
For i = 1 To numrows
Rows(i + ar).Insert
Cells(i + ar, 1) = Cells(i - 1 + ar, 1) + 1
Next i
End Sub

'This one will put in numbers starting with 1 to numrows
Sub InsertRowsAndNumberFrom1()'SalesAidSoftware
numrows = InputBox("Number of rows")
Rows(ActiveCell.Row).Resize(numrows).Insert
With ActiveCell.Resize(numrows)
.Formula = "=INT(ROW(A1)-1+1)"
.Value = .Value
End With
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Robin" wrote in message
...
I agree. Here is the original question.
Have code that automatically copies a row and then inserts new rows in a
worksheet that are copies of that row, based on a number entered by a user
through an InputBox. The first cell in the row contains a number that
needs
to increment as the new rows are inserted. In other words, in the row
that
is copied there is a cell with a value of '1' and I need that value to be
incremented for each new row that is inserted. So, if Excel inserts ten
additional rows, that number should be incremented from '1' in the copied
row
all the way to '11' in the newly inserted rows.


Here is the code


Here is the code that copies and inserts the 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

Thanks!




All times are GMT +1. The time now is 02:23 PM.

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