简体   繁体   English

如何在VBA上锁定单元格?

[英]How to Lock a Cell on VBA?

Need some help in making a cell edit proof on a Time Stamp, Here is the code I am using : 在制作时间戳上的单元格编辑证明时需要一些帮助,这是我正在使用的代码:

Sub Start()
    Range("A2").Value = Now()
End Sub

Basically I don't want an user to have access to edit the time stamp on Cell A2 . 基本上,我不希望用户有权编辑单元格A2上的时间戳。 . Any help will be appreciated..Thanks in advance :) 任何帮助将不胜感激..在此先感谢:)

What about using Sheet protection? 使用工作表保护怎么办?

Sub Start()
   'unprotect sheet to edit locked cells'
   ActiveSheet.Unprotect
   'set other cells to be unlocked (I've add this line only because in my excel all cells are locked by defalut, you can delete this line'
   Cells.Locked = False
   'change A2 and make it locked'
   With Range("A2")
       .Value = Now()
       .Locked = True
   End With
   'protect sheet for not allowing change locked cells'
   ActiveSheet.Protect
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM