Insert "X" number of Rows Based on User Input

activeman

New Member
Joined
Mar 1, 2011
Messages
15
Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p> </o:p>
Using Excel VBA I am looking to automate a basic Copy and Paste routine which amounts to little more than copying row 3 and then pasting it in the next blank row below.<o:p></o:p>
<o:p> </o:p>
However I want the User to decide on the “number” of rows they want pasting into the Worksheet based on an input box.<o:p></o:p>
<o:p> </o:p>
Based on this “number” the macro will copy row 3 find the next blank row and copy row 3 the applicable “number” of times as determined by the User.<o:p></o:p>
<o:p> </o:p>
E.g. <o:p></o:p>
Run Macro<o:p></o:p>
Input Box asks User how many rows they would like pasting?<o:p></o:p>
User Inputs “50”<o:p></o:p>
Macro copies Row 3 and then pastes row 3 into the next blank row 50 times over<o:p></o:p>
<o:p> </o:p>
Any help would be much appreciated?<o:p></o:p>
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Hi,

Maybe something like this?

Code:
Sub InsertRows()

    Dim lngRows As Long, lngNextRow As Long

    On Error GoTo Finish

    lngRows = CLng(InputBox("How many rows do you wish to insert?"))
    lngNextRow = Range("A" & Rows.Count).End(xlUp).Row + 1
    
    Rows(3).Copy Rows(lngNextRow & ":" & lngNextRow + lngRows - 1)
       
Finish:
    If Err.Number <> 0 Then MsgBox Prompt:="Please ensure you only enter numeric values!"

End Sub
 
Upvote 0
Hi,

Maybe something like this?

Code:
Sub InsertRows()
 
    Dim lngRows As Long, lngNextRow As Long
 
    On Error GoTo Finish
 
    lngRows = CLng(InputBox("How many rows do you wish to insert?"))
    lngNextRow = Range("A" & Rows.Count).End(xlUp).Row + 1
 
    Rows(3).Copy Rows(lngNextRow & ":" & lngNextRow + lngRows - 1)
 
Finish:
    If Err.Number <> 0 Then MsgBox Prompt:="Please ensure you only enter numeric values!"
 
End Sub

I am attempting to adjust the above code so rather than copying and pasting row 3 it copies and pastes the FORMULA's ONLY from row 3.

Not getting too far would anyone have any ideas how to do this?
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,845
Members
452,948
Latest member
UsmanAli786

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