PDA

View Full Version : [SOLVED:] Run time Error 1004 when assigning cell value



BoaredGamer
01-17-2022, 12:32 AM
I have been making some changes to a sheet in my workbook (sheet template) adding in a new section in the worksheet changed event to update the format and unlock cells to allow people to fill in somewhere down the line it was working I'm not sure when, then after a few more changes it started to give me 1004 errors when assigning new values to cells, to the point where when running the sub test in module 4 on the template sheet


Sub test()
Range("A1").Value = 0
End Sub

gives me a 1004 error

can anyone tell me why

29322

BoaredGamer
01-17-2022, 12:43 AM
Sorry for bothering everyone, but I seem to keep finding the solution right after I post

As it turns out I forgot to delete a line


ActiveSheet.Protect

In one of the functions I called after deciding to move the Protect and Unprotect to encompass the whole event to simplify coding

And so the reason for the 1004 error was because it was attempting to assign a value to a locked cell on a protected sheet.

arnelgp
01-17-2022, 01:09 AM
try manually entering value to Cell A1 of Template worksheet.
what do you get? is the sheet protected? then unprotect it first before
you put some values.

Sub test()
With ActiveSheet
.Unprotect
.Range("A1").Value = 0
.Protect
End With
End Sub