Googleで見つけたこのコードを取得しました。( http://msgroups.net/microsoft.public.excel.misc/locking-cells-automatically-after/45998 ) 仕事でこれが必要です。-編集: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