如何锁定VBA上的单元格?

时间:2014-01-08 20:07:22

标签: excel excel-vba vba

在时间戳上制作单元格编辑证明需要一些帮助,这是我正在使用的代码:

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

基本上我不希望用户有权编辑单元格A2上的时间戳。 。任何帮助将不胜感激。谢谢提前:))

1 个答案:

答案 0 :(得分:1)

使用表格保护怎么样?

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