我使用更改事件创建了一个vba代码,用于在同一工作簿的“日志表”中记录时间戳。每当同一工作簿的“ ProjectEntry”表的AG列中的值更改时,都必须在“日志表”中标记时间和当前值。但是,如果“ ProjectEntry”列的AG中没有更改,则不应触发该宏。
我使用相交是否达到这一目的,但这是行不通的。代码如下。我将更改事件放置在“ projectEntry”表上。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim strAddress As Long
Dim dtmTime As Date
Dim Rw As Long
Dim task As String
Dim status
Dim rng As Range
Set rng = Range("AG:AG")
If Intersect(Target, rng) Is Nothing Then Exit Sub
dtmTime = Now()
status = Target.Value
strAddress = Target.row
task = Cells(strAddress, 3).Value
Rw = Sheets("Log Sheet").Range("A" & Rows.Count).End(xlUp).row + 1
With Sheets("Log Sheet")
.Cells(Rw, 1) = task
.Cells(Rw, 2) = status
.Cells(Rw, 3) = dtmTime
End With
End Sub
此工作簿是一个查询,每更新10分钟便会更新一次,vba必须在AG列中查找问题。如果没有更改,则不会更新日志表。但是相反,每次更新都在“日志表”中键入Task-#-time。
Task -- Status -- Time stamp
SRFE045 -- Customer Review -- 5/9/2019 16:46
EECR-PDmeter cover -- Rework -- 5/10/2019 10:45
SPJ-WCM-CRN-PRE ENGINEERING -- Customer Review -- 5/13/2019 12:50
SPJ-Tapered trim updates -- In progress -- 5/13/2019 17:02
Task -- # -- 5/13/2019 17:03
Task # 5/13/2019 17:13
Task # 5/13/2019 17:23
Task # 5/13/2019 17:33
Task # 5/13/2019 17:43
Task # 5/13/2019 17:53
Task # 5/13/2019 18:04
Task # 5/13/2019 18:14
Task # 5/13/2019 18:24
第一行是标题 此后预期输出4行,因为此“日志表”中不应显示其余的行。
根据我的理解,当没有相交时,应该退出sub。但它没有退出,即使没有相交,它也正在初始化“ ProjectEntry”工作表的行标题。不知道为什么会这样。
下面是“项目条目”表中的标题
#
Entry Date
Task
Description
Work Type
Priority
Expected Hours
Expected Due Date
Target completion Date
ECN Type
Responsible Engineer
Start Date
Status
Comments
ECN #
Reviewer
ECN Initiation Date 1st time
Billed Hours
ECN Released Date
ECN initiation Date
Delay Days
Total Hours
Hours Tally
Count Project
count delays
Processing Days
Turn Around Days
Execution Days
Target
Yield
Expected Hours Before
Target Completion date Before
Status Before