Hi There,
I have the following code pasted below attached to a button:
This is really annoying me because the code works if the worksheet is unprotected BEFORE running the macro.
However if the worksheet is protected the code produces the following error '1004' Paste special method of range class failed.
***Note that values have been copied on an outside sheet and this macro is only being run with copied cell data.
Please help.
Sub InputData()
'Unprotect sheet to allow formula to be pasted in locked cells
Worksheets("Sheet1").Unprotect Password:="MontyBurns69!"
'Unhide sheet and hide homepage sheet
Sheets("Sheet1").Visible = True
Sheets("Sheet1").Select
Sheets("DatabaseHomepage").Visible = False
'Select the cell after the last entered row.
Range("A" & Rows.Count).End(xlUp).Offset(1).Select
'Paste data that was copied from outside spreadsheet as values into the selected cell.
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Reprotect Worksheet
Worksheets("Sheet1").Protect Password:="MontyBurns69!"
End Sub
I have the following code pasted below attached to a button:
This is really annoying me because the code works if the worksheet is unprotected BEFORE running the macro.
However if the worksheet is protected the code produces the following error '1004' Paste special method of range class failed.
***Note that values have been copied on an outside sheet and this macro is only being run with copied cell data.
Please help.
Sub InputData()
'Unprotect sheet to allow formula to be pasted in locked cells
Worksheets("Sheet1").Unprotect Password:="MontyBurns69!"
'Unhide sheet and hide homepage sheet
Sheets("Sheet1").Visible = True
Sheets("Sheet1").Select
Sheets("DatabaseHomepage").Visible = False
'Select the cell after the last entered row.
Range("A" & Rows.Count).End(xlUp).Offset(1).Select
'Paste data that was copied from outside spreadsheet as values into the selected cell.
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Reprotect Worksheet
Worksheets("Sheet1").Protect Password:="MontyBurns69!"
End Sub