0

My cell is locked and I am filling the cell with data on Worksheet_Change event of a drop-down: Format(Date, "mm-dd-yyyy").

I am getting following error :: Run-time error '1004': Application-defined or object-defined error

I do not want to unlock the field as it is to be non-editable.

I also do understand that it is giving the error just because the cell is locked and it needs to perform the operation: Format(Date, "mm-dd-yyyy")..

What options do I have to make it working without unlocking the cell?

1 Answer 1

1

Unlock the sheet, then make changes as needed, then lock again.

Me.Unprotect "pwd"
Me.Range("A1").Value = Format(Date,"mm-dd-yyyy")
Me.Protect "pwd"
Sign up to request clarification or add additional context in comments.

4 Comments

I am not using a password to protect .... I am just using the following:ActiveSheet.Unprotect ActiveSheet.Range(ActiveSheet.Cells(S, 1), ActiveSheet.Cells(S + 9, lColumn)).Locked = True ActiveSheet.Protect .. Please do let me know how to do using this approach..
@sid - Just take the password out and pass "". Otherwise, I am confused. You can just set the format (or cell value) in between protection and unprotection. Because locking a cell is meaningless when worksheet is unprotected state.
This is not working ... I am setting the ActiveSheet.Range().locked = False and then setting the value and then setting ActiveSheet.Range().Locked = True ... This is how the code looks like ActiveSheet.Range(ActiveSheet.Cells(rps + 3, cps)).Locked = False Cells(rps + 3, cps).Value = Format(Date, "mm-dd-yyyy") ActiveSheet.Range(ActiveSheet.Cells(rps + 3, cps)).Locked = True
What I also found out is that when I click on the drop-down and select and option 2 things are happening: 1) A String in a cell is populated and 2) A date in a cell is populated ... Both the cells are locked .. .while it is able to write String to a locked cell BUT its giving"Application-defined OR Object-defined" Error while entering date. ??? What could be the reason...... Why excel vba is able to enter string in a locked cell but unable to enter date in a locked cell ?? Please help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.