gpt4 book ai didi

excel - 根据条目在 excel 中创建自动日期戳

转载 作者:行者123 更新时间:2023-12-04 06:53:26 25 4
gpt4 key购买 nike

当在 A 列中输入条目时,我试图在 B 列中发生日期戳事件。现在我可以在 VBA 中毫无问题地执行此操作,我遇到的问题是还有一个条目最终会进入比如说 D 列,并且在 E 列中也需要一个日期戳。这可能吗。这是我迄今为止使用的代码示例。

Private Sub Worksheet_Change(ByVal Target As Range)
对于目标中的每个单元格
如果 Cell.Column <= 3 那么
If Cells(Cell.Row, 1) <> ""Then Cells(Cell.Row, 2) = Now
万一
下一个单元格
结束子

最佳答案

如果您对用户输入的每个奇数列都满意,并且时间戳在偶数列中(即您可以在 A 列中输入,而时间戳将在 B 列中输入。您可以在 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

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

关于excel - 根据条目在 excel 中创建自动日期戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2800030/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com