我有一个单元格,用于说明项目的状态,并且此状态会经常更改。
无论状态如何更改,我都希望在一行中声明状态更改的时间以及新状态的名称。
我几乎没有VBA的经验,因此我们将不胜感激。到目前为止,我有这个:
{{1}}
只要单元格D4中包含的状态发生更改,此代码就成功列出了单元格G7中的时间,但是它总是重新填充同一单元格,我希望每个连续的状态更改都在单元格G8中依次列出日期戳,然后是G9,然后是G10 , 等等。
它也不会列出状态单元格D4的更改,理想情况下,我希望将其列在F7,F8,F9等中。
答案 0 :(得分:2)
x.Column_A = "Data_Result"
上的Worksheet_Change
感兴趣,则可以使用下面显示的D4
方法Intersect
中最后使用的单元格并相应地偏移Column G
答案 1 :(得分:-1)
请尝试这个。
Private Sub Worksheet_Change(ByVal Target As Range)
Const Tgt As String = "D4" ' monitored cell
Const FirstRecord As Long = 7 ' change as required
Const Fmt As String = "yyyy-mm-dd hh:mm:ss"
Dim Rl As Long ' last used row
If Target.Address = Range(Tgt).Address Then
Application.EnableEvents = False
Rl = Application.WorksheetFunction.Max( _
Cells(Rows.Count, "F").End(xlUp).Row + 1, FirstRecord)
With Cells(Rl, "G")
.Value = Now()
.NumberFormat = Fmt
Target.Copy Destination:=.Offset(0, -1)
End With
Application.EnableEvents = True
End If
End Sub