一旦所有的单元格被填入,时间戳记
这是情况
列A
到列G
被devise为下拉列表(数据validation):姓名,号码,ID,电话等。到达办公室后,每个员工必须将他们的信息填入该行的每个单元格,列A到G.
我想从一个VBA代码:
只有当每个单元格填入A:G
,date和时间才会在相应单元格的H列中加盖。这是永久性的。 它不会改变。 一旦date被盖印,单元格A:G
也被locking。
我的编码到目前为止:
Private Sub Worksheet_Change(ByVal Target As Range) If Target.Column = 1 Then Target.Offset(0,1) = Now End If End Sub
此时间戳只有列A中的单元格更改:(
我应该使用“case select”语句吗?
这是你正在尝试? (试验和testing)
Option Explicit '~~> Change this to the relevant password Const MYPASSWORD As String = "BlahBlah" Private Sub Worksheet_Change(ByVal Target As Range) If Target.Cells.CountLarge > 1 Then Exit Sub On Error GoTo Whoa Application.EnableEvents = False Dim rng As Range Dim nRow As Long nRow = Target.Row Set rng = Range("A" & nRow & ":G" & nRow) '~~> Check if all cell from AG are filled and '~~> There is no time stamp already there If Application.WorksheetFunction.CountA(rng) = 7 _ And Len(Trim(Range("H" & nRow).Value)) = 0 Then ActiveSheet.Unprotect MYPASSWORD Range("H" & nRow).Value = Now Range("A" & nRow & ":H" & nRow).Locked = True ActiveSheet.Protect MYPASSWORD End If Letscontinue: Application.EnableEvents = True Exit Sub Whoa: MsgBox Err.Description Resume Letscontinue End Sub