在Excel中创build一个自动date戳

我想在A列中input条目时在列B中发生date戳事件。现在,我可以在VBA中执行此操作,没有任何问题,我遇到的问题是还有一个条目最终会进入说D列,并且还需要列E中的date戳。 这可能吗。 这里是我迄今使用的代码示例。

Private Sub Worksheet_Change(ByVal Target As Range)对于目标中的每个单元格如果Cell.Column <= 3那么如果单元格(Cell.Row,1)<>“”那么Cells(Cell.Row,2)= Now End If Next Cell结束小组

如果用户input的每个奇数列都可以,并且时间戳在偶数列中(即,可以在列A中键入,而时间戳将在列B中),则可以input。您可以键入C列和时间戳会在D列等),那么你可以使用这个:

Private Sub Worksheet_Change(ByVal Target As Range) 'Only write a timestamp of an odd column changes (because the timestamps go in the even columns) If Target.Column Mod 2 > 0 Then 'Get the first part of the address, to get the actual column being changed Dim columnAddress As String columnAddress = Target.Address If InStr(columnAddress, ":") > 0 Then columnAddress = Left(columnAddress, InStr(columnAddress, ":") - 1) End If 'This will cause the TimeStamp to be undeletable (kind of like na Audit). 'If you want the timestamp to disappear when you clear the column, uncomment the next few lines: ' If Not ActiveSheet.Range(columnAddress).Formula = "" Then ''Write the timestamp for the previous column ActiveSheet.Range(columnAddress).Offset(0, 1).Formula = Now ' Else ' ActiveSheet.Range(columnAddress).Offset(0, 1).Formula = "" ' End If End If End Sub 

您可以隐藏不需要显示时间戳的列。