Hi All
I have the following code that copies data, opens another workbook, selects a sheet and pastes onto the next available row. It works beautifully.
However, I need to have the "Submitted Data" sheet protected so I added code to unprotect the sheet, paste the data and then protect the sheet again as below.
The sheet gets unprotected but I get Run-Time error '1004' PasteSpecial method of Range class failed.
If I remove the protection and the associated code, then it works but I lose the protection.
Any ideas on what is going wrong?
Thanks
I have the following code that copies data, opens another workbook, selects a sheet and pastes onto the next available row. It works beautifully.
Code:
Sub Submit()If MsgBox("Are you sure you want to submit data?", vbYesNo) = vbNo Then
Exit Sub
Else
MsgBox ("If you need to make changes please submit again.")
Sheets("Sheet1").Range("A3:S3").Copy
Workbooks.Open Filename:="N:\Location\File.xlsm", Password:="password"
Sheets("Submitted Data").Activate
With Sheets("Submitted Data").Range("A" & Rows.Count).End(xlUp).Offset(1)
.PasteSpecial Paste:=xlPasteColumnWidths
.PasteSpecial Paste:=xlPasteValues
End With
Workbooks("File.xlsm").Close SaveChanges:=True
End If
End Sub
However, I need to have the "Submitted Data" sheet protected so I added code to unprotect the sheet, paste the data and then protect the sheet again as below.
Code:
Sub Submit()If MsgBox("Are you sure you want to submit data?", vbYesNo) = vbNo Then
Exit Sub
Else
MsgBox ("If you need to make changes please submit again.")
Sheets("Sheet1").Range("A3:S3").Copy
Workbooks.Open Filename:="N:\Location\File.xlsm", Password:="password"
Sheets("Submitted Data").Activate
[COLOR=#ff0000]ActiveSheet.Unprotect "password"[/COLOR]
With Sheets("Submitted Data").Range("A" & Rows.Count).End(xlUp).Offset(1)
.PasteSpecial Paste:=xlPasteColumnWidths
.PasteSpecial Paste:=xlPasteValues
End With
[COLOR=#ff0000]ActiveSheet.Protect "password"[/COLOR]
Workbooks("File.xlsm").Close SaveChanges:=True
End If
End Sub
The sheet gets unprotected but I get Run-Time error '1004' PasteSpecial method of Range class failed.
If I remove the protection and the associated code, then it works but I lose the protection.
Any ideas on what is going wrong?
Thanks