Copy & paste to protected sheet

N

nc

I am using the macro below, where would I insert the unprotect and protect
statement for the sheet "Transactions", the latter is protected.


sub CopyStatement()

Dim LastRow As Long


CopyStatementMsg = MsgBox("Are you sure you want to Copy Statement to
Transactions Sheet?", vbYesNo + vbDefaultButton2)

If CopyStatementMsg = vbNo Then End

Application.ScreenUpdating = False

ActiveSheet.Unprotect


ActiveSheet.UsedRange
LastRow = Cells.SpecialCells(xlLastCell).Row
LastRow = Cells(Cells.Rows.Count, "W").End(xlUp).Row
ActiveSheet.Range("$S$5:$W" & LastRow).Copy
Sheets("Transactions").Range("A13").PasteSpecial Paste:=xlValues
ActiveSheet.Protect

Sheets("Transactions").Activate
Range("F13").Select


Application.ScreenUpdating = True


End Sub
 
S

Shane Devenshire

Hi,

Avoid this issue by programatically protecting the worksheet and using the
ActiveSheet.Protect Password:="x", UserInterfaceOnly:=True

You can run this as a stand alone macro or you can incorporate this into a
Workbook_Open procedure.
 
N

nc

Sorry, your answer was not helpful.

Basically I am just protecting the worksheets with formulas to avoid
accidentally deleting them.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top