VBA Copy Row and Paste as Formulas "X" number of times

activeman

New Member
Joined
Mar 1, 2011
Messages
15
I have been kindly supplied with the following code that allows the Document User to define the number of rows to be inserted in a Worksheet.

Currently this code copies row 3 and pastes it the defined number of times beneath the last used row.

However I would like to tweak the code so that rather than pasting all of row 3 into the Worksheet I would like it to only paste the formulas from row 3.

Unfortunately my VBA is no where near good enough to work this one out so would anyone else have any ideas?

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

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Add 1 row:

Rich (BB 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)
Rows(lngNextRow & ":" & lngNextRow + lngRows - 1).SpecialCells(2).ClearContents

Finish:
If Err.Number <> 0 Then MsgBox Prompt:="Please ensure you only enter numeric values!"

End Sub

That line will delete all cells, in the chosen rows, containing fixed constants. So the formulas remain.

Please use code tags when you paste code on the forum here. It makes code much more readable.

Wigi
 
Upvote 0

Forum statistics

Threads
1,215,148
Messages
6,123,309
Members
449,095
Latest member
Chestertim

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