在一张 Excel 工作表上添加超过 1 个时间戳
Add more than 1 timestamp on one Excel Worksheet
我有一些问题...
我有一项工作 sheet 来跟踪 CRM 管道活动,每个状态更改都将通过时间戳记录...但是,我不知道如何制作多个时间戳.. .
这里的条件:
单元格“A”将作为范围和触发器,然后单元格“B”将作为
目标时间戳 I.
单元格“G”将作为范围和触发器,然后单元格“H”将作为目标时间戳 II.
单元格“P”将作为范围和触发器,然后单元格“Q”将作为目标时间戳 III.
单元格“AA”将作为范围和触发器,然后单元格“AB”将作为目标时间戳 IV。
范围和触发值可以是数字 and/or 文本。
这是我的作品sheet代码:
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
工作表更改:多个时间戳列
- 仅当 'timestamp cell' 为空时才会添加时间戳。
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
我有一些问题...
我有一项工作 sheet 来跟踪 CRM 管道活动,每个状态更改都将通过时间戳记录...但是,我不知道如何制作多个时间戳.. .
这里的条件:
单元格“A”将作为范围和触发器,然后单元格“B”将作为 目标时间戳 I.
单元格“G”将作为范围和触发器,然后单元格“H”将作为目标时间戳 II.
单元格“P”将作为范围和触发器,然后单元格“Q”将作为目标时间戳 III.
单元格“AA”将作为范围和触发器,然后单元格“AB”将作为目标时间戳 IV。
范围和触发值可以是数字 and/or 文本。
这是我的作品sheet代码:
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
工作表更改:多个时间戳列
- 仅当 'timestamp cell' 为空时才会添加时间戳。
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