简体   繁体   English

VBA 锁定一个单元格

[英]VBA to Lock one Cell

I'm trying to lock J7 from being edited but can't seem to get the code right to do so.我试图锁定 J7 不被编辑,但似乎无法获得正确的代码。 Any suggestions as to how I may adjust the Worksheet selection change code below would be appreciated!关于如何调整下面的工作表选择更改代码的任何建议将不胜感激!

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
 
If Target.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("G26:BA9999")) Is Nothing And Range("G" & Target.Row).Value <> Empty Then
    Range("B2").Value = Target.Row
    Initiative_Load

End If

If Not Intersect(Target, Range("L17,L19,U3,U5,U7,U9,U11,U13,U15,U17,U19,U21")) Is Nothing Then
    CalendarFrm.Show

End If

If Not Intersect(Target, Range("J7")) Is Nothing Then
    Range("J7").Locked = True

End If

End
End Sub

In general:一般来说:

  1. Insure the worksheet is un-protected.确保工作表不受保护。
  2. Adjust the Lock/Unlock status of a cell or group of cells.调整单元格或单元格组的锁定/解锁状态。
  3. Re-protect the worksheet.重新保护工作表。

Sub Lock_J7()
    Sheets("Sheet1").Unprotect Password:="secret"
        Cells.Locked = False
        Range("J7").Locked = True
    Sheets("Sheet1").Protect Password = "secret"
End Sub

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

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