我得到了我在谷歌找到的这段代码。 (http://msgroups.net/microsoft.public.excel.misc/locking-cells-automatically-after/45998) 我需要这个工作。 -EDIT:我在EXCEL中已经知道了Excel锁和网格错误
当前网格中的所有单元格都未锁定。 我想要做的是在输入数据 后,单元格会自动锁定。
我需要代码工作的最高列“J”和无限的行。 我在google中获得的这段代码最多只能使用25x25: 如果单元格清空或空白,则密码保护不应起作用,即使之前有数据,也可以自由输入。
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myRng As Range
Dim myCell As Range
Dim myIntersect As Range
Dim myPassword As String
myPassword = "hi there"
With Me 'the worksheet with the code
'25 rows by 25 columns starting in A1
Set myRng = .Range("a1").Resize(25, 25)
Set myIntersect = Intersect(Target, myRng)
If myIntersect Is Nothing Then
Exit Sub
End If
.Unprotect Password:=myPassword
For Each myCell In myIntersect.Cells
myCell.Locked = True
Next myCell
.Protect Password:=myPassword
End With
End Sub
只锁定单元格或锁定整个工作表? – Kasnady 2013-04-24 08:14:20
进入特定单元后锁定 – 2013-04-24 08:49:47
在寻求帮助之前尝试努力。我们只是帮助解决错误。无助于在家工作 – Kasnady 2013-04-25 00:53:38