Macro to copy last row down

karabiner8

Board Regular
Joined
Jan 11, 2005
Messages
50
I searched and searched but all the solutions I've found seem to have some little twist to them and I'm not knowledgeable enough to change the code to suit my situation. Here is what I am trying to do (Excel 2003 on XP).

I have a large table where the user enters data. Some columns are for data entry and others have formulas. The formula columns are locked and the worksheet is password protected.

I need a macro that will find the last row of the table and copy it down X numbers of rows. It should allow the user to enter the number of extra rows that they need. For simplicity it can just select the entire last row of the table and copy it down X number of times. The macro should then re-protect the worksheet. The first formula column is W.

Thanks
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
This might do it:
Code:
Option Explicit

Sub AddRowsOnProtectedSheets()
Dim Rws As Long, LR As Long

Rws = Application.InputBox("How many rows to add?", "Add Rows", Type:=1)
If Rws = 0 Then Exit Sub

Application.ScreenUpdating = False
ActiveSheet.Unprotect "password"

'Find last row
    LR = Range("W" & Rows.Count).End(xlUp).Row
'copy that row
    Range("A" & LR).EntireRow.Copy Range("A" & LR + 1).Resize(Rws)
'remove any non-formulas
    On Error Resume Next
    Range("A" & LR + 1).Resize(Rws).EntireRow.SpecialCells(xlCellTypeConstants).ClearContents

ActiveSheet.Protect "password"
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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