在一个Excel工作表上添加超过1个时间戳

发布于 2025-01-31 11:43:08 字数 1146 浏览 1 评论 0原文

我有一些问题...

我有一个工作表可以跟踪CRM管道活动,并且更改的每个状态都会通过时间戳记录...但是,我不知道如何制作一个以上的时间戳记...

在这里条件:

  • 单元格“ a”将为范围和触发,然后单元格“ b”将为 目标时间戳I。

  • 目标时间戳
  • 单元格“ p”将是范围和触发,然后单元格“ q”为目标时间戳iii。

  • 单元格“ AA”将是范围和触发,然后单元格“ AB”将为目标时间戳IV。

  • 范围和触发值可以为数字和/或文本。

这是我的工作表代码:

Private Sub Worksheet_Change(ByVal Target As Range)

Dim myTableRange1 As Range
Dim myTrigger1 As Range
Dim myUpdatedRange1 As Range

'Your data table range
Set myTableRange1 = Range("B6:B50000")

'Check if the changed cell is in the data tabe or not.
If Intersect(Target, myTableRange1) Is Nothing Then Exit Sub

'Stop events from running
Application.EnableEvents = False

'Column for the date/time
Set myTrigger1 = Range("B" & Target.Row)

'Column for last updated date/time
Set myUpdatedRange1 = Range("G" & Target.Row)

'Determine if the input date/time should change
If myTrigger1.Value = "" Then

myUpdatedRange1.Value = Now   

End If

'Update the updated date/time value
myUpdatedRange1.Value = Now

'Turn events back on
Application.EnableEvents = True
End Sub

I have some issue...

I have a work sheet to track CRM pipeline activities and every status changed will be recorded by a time stamp... but, I don't know how to make more than one time stamp...

Here the condition:

  • Cell "A" will be as Range and Trigger, Then Cell "B" will be as
    target timestamp I.

  • Cell "G" will be as Range and Trigger, Then Cell "H" will be as target timestamp II.

  • Cell "P" will be as Range and Trigger, Then Cell "Q" will be as target timestamp III.

  • Cell "AA" will be as Range and Trigger, Then Cell "AB" will be as target timestamp IV.

  • The Range and Trigger Values can be as number and/or text.

This my Worksheet Code:

Private Sub Worksheet_Change(ByVal Target As Range)

Dim myTableRange1 As Range
Dim myTrigger1 As Range
Dim myUpdatedRange1 As Range

'Your data table range
Set myTableRange1 = Range("B6:B50000")

'Check if the changed cell is in the data tabe or not.
If Intersect(Target, myTableRange1) Is Nothing Then Exit Sub

'Stop events from running
Application.EnableEvents = False

'Column for the date/time
Set myTrigger1 = Range("B" & Target.Row)

'Column for last updated date/time
Set myUpdatedRange1 = Range("G" & Target.Row)

'Determine if the input date/time should change
If myTrigger1.Value = "" Then

myUpdatedRange1.Value = Now   

End If

'Update the updated date/time value
myUpdatedRange1.Value = Now

'Turn events back on
Application.EnableEvents = True
End Sub

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

轮廓§ 2025-02-07 11:43:08

工作表更改:多个时间戳列,

  • 这只有在“时间戳牢房”为空白时,才会添加时间戳。
Private Sub Worksheet_Change(ByVal Target As Range)
    
    Const FirstRow As Long = 6
    Const ColumnsRangeAddress As String = "A:A,G:G,P:P,AA:AA"
    
    Dim srg As Range: Set srg = Intersect(Rows(FirstRow) _
        .Resize(Rows.Count - FirstRow + 1), Range(ColumnsRangeAddress))
    
    Dim irg As Range: Set irg = Intersect(srg, Target)
    If irg Is Nothing Then Exit Sub
    
    Dim drg As Range
    Dim iCell As Range
    
    For Each iCell In irg.Cells ' 'A,G,P,AA'
        With iCell.Offset(, 1) ' 'B,H,Q,AB'
            If Len(CStr(.Value)) = 0 Then ' is blank
                If drg Is Nothing Then
                    Set drg = .Cells
                Else
                    Set drg = Union(drg, .Cells)
                End If
            'Else ' is not blank; do nothing
            End If
        End With
    Next iCell
    
    If drg Is Nothing Then Exit Sub
    
    Application.EnableEvents = False ' before writing
    drg.Value = Now
    Application.EnableEvents = True ' after writing

End Sub

A Worksheet Change: Multiple Timestamp Columns

  • This will add a timestamp only if the 'timestamp cell' is blank.
Private Sub Worksheet_Change(ByVal Target As Range)
    
    Const FirstRow As Long = 6
    Const ColumnsRangeAddress As String = "A:A,G:G,P:P,AA:AA"
    
    Dim srg As Range: Set srg = Intersect(Rows(FirstRow) _
        .Resize(Rows.Count - FirstRow + 1), Range(ColumnsRangeAddress))
    
    Dim irg As Range: Set irg = Intersect(srg, Target)
    If irg Is Nothing Then Exit Sub
    
    Dim drg As Range
    Dim iCell As Range
    
    For Each iCell In irg.Cells ' 'A,G,P,AA'
        With iCell.Offset(, 1) ' 'B,H,Q,AB'
            If Len(CStr(.Value)) = 0 Then ' is blank
                If drg Is Nothing Then
                    Set drg = .Cells
                Else
                    Set drg = Union(drg, .Cells)
                End If
            'Else ' is not blank; do nothing
            End If
        End With
    Next iCell
    
    If drg Is Nothing Then Exit Sub
    
    Application.EnableEvents = False ' before writing
    drg.Value = Now
    Application.EnableEvents = True ' after writing

End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文