PDA

View Full Version : Run time Error on Save Data



snowdyce
07-17-2014, 07:56 AM
I have some code in the ThisWorkbook section that runs when the workbook is saved. The code is simple, copies a value from one cell to another. It was working fine, but lately I am getting the Run time error '1004'. Bewlo if the code, the Debug hits the first one.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)



'On Save, copy Contex members from Sheet 1 to Sheet 2
Worksheets("Sheet2").Cells(6, 4).Value = Worksheets("Sheet1").Cells(6, 4).Value
Worksheets("Sheet2").Cells(7, 4).Value = Worksheets("Sheet1").Cells(7, 4).Value
End Sub


Thanks!

westconn1
07-17-2014, 02:30 PM
try prefixing the all sheet references with thisworkbook.

snowdyce
07-18-2014, 05:46 AM
Thanks Westconn1, but that did not work. Same error still exists when attempting to save the file.

11979

westconn1
07-18-2014, 03:29 PM
you haven't changed the sheet names or anything similar?

snowdyce
07-22-2014, 07:02 AM
I have not, they are still both names Sheet1 and Sheet2

westconn1
07-22-2014, 02:21 PM
can you edit cells in the same sheets by code from other procedures?
have the sheets been protected?

test if the error is with sheet1 or sheet2

does it happen in a new workbook?
post a copy of the workbook (remove any sensitive information), make sure the error still occurs

snowdyce
07-23-2014, 05:48 AM
I fond the issue, the sheet did get protected somehow. Once I unprotected it the code ran fine. Thank you for your help westconn1!