如果这是一个愚蠢的问题,请道歉,但我是新手。
我确信这是一个简单的解决方法,但我无法理解。
我希望能够同时运行两个VBA。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim xRg As Range
On Error Resume Next
Set xRg = Intersect(Range("J2:J40"), Target)
If xRg Is Nothing Then Exit Sub
Target.Worksheet.Unprotect Password:="PW"
xRg.Locked = True
Target.Worksheet.Protect Password:="PW"
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim xCellColumn As Integer
Dim xTimeColumn As Integer
Dim xRow, xCol As Integer
xCellColumn = 10
xTimeColumn = 9
xRow = Target.Row
xCol = Target.Column
If Target.Text <> "" Then
If xCol = xCellColumn Then
Cells(xRow, xTimeColumn) = Now()
End If
End If
End Sub
有人可以帮我吗?
答案 0 :(得分:0)
如果编辑的Cell位于J列(第2行或更高),而Target只包含一个Cell
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Const PW = "PW"
With Target
If .Column = 10 And .Row > 1 And .CountLarge = 1 Then 'J2:J(lastRow)
.Worksheet.Unprotect Password:=PW
If Len(.Value2) > 0 Then
Application.EnableEvents = False
.Offset(, -1) = Now
Application.EnableEvents = True
End If
.Locked = True
.Worksheet.Protect Password:=PW
End If
End With
End Sub