excel insert rows and paste incremental value

cstephens

New Member
Joined
Jan 17, 2011
Messages
12
I need to insert a random number of rows in excel and fill the cell value incrementally by one on each row.
I found the following formula that inserts the blanks rows and copies the value to each row. I want the value to increment by 1 for each new row. It prompts the user for the number of rows to add. But it inserts the row and copies the value down. I need the value to be copied down but add one to the value each time it is copied.
Ex prompt for the number of rows to insert. User enters value of 3. So 3 rows should be inserted. If the value was 111 the next row the cell value would be 112 and the next would be 113, the next 114

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 for any help that can be provided.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
here is one way

Code:
Sub copyrows()
Dim numrows As Long, Srow As Long, SValue As Long
numrows = InputBox("Number of rows")
RValue = InputBox("What is the next row value to be entered", "Next value", 111)
Srow = ActiveCell.Row
Rows(ActiveCell.Row).Copy
Rows(Srow).Resize(numrows).Insert
Application.CutCopyMode = False
For i = Srow To Srow + numrows
    Cells(i, 1) = RValue
    RValue = RValue + 1
Next i
End Sub
 
Upvote 0
Item number is in row one column A, column B = description, column C = qty, column D will be serial number.
row two column A = a different item, B = desc, C = Qty, D = serial number.
The number of rows inserted will equal to the qty column the serial number will be incremented by one for each new inserted row. It will break on item.
 
Upvote 0
Ok. Things have changed. Now I need the capability to put an alphabetical character in front of the numbers.
After the prompt for the number of rows. I need another prompt to ask for the prefix. Ex T
then when the value is incremented by one the T would be added or concatenated to the front of the value ex T111 then the next row would be T112 and so on. If an alphabetical character is not entered at the prompt then the value would just be 111 then 112 the way you wrote the formula above.
Help on this would greatly be appreciated.
 
Upvote 0
change this
Cells(i, 1) = RValue
to the column number or you can use like
Cells(i, "a") = RValue
 
Upvote 0

Forum statistics

Threads
1,215,332
Messages
6,124,313
Members
449,152
Latest member
PressEscape

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top