下面是我用来通过更改时单元格返回不同值来跟踪每张纸变化的代码。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim strAddress As String
Dim val
Dim dtmTime As Date
Dim Rw As Long
If Intersect(Target, Range("A:AZ")) Is Nothing Then Exit Sub
'change range to suit
dtmTime = Now()
With Target
val = .Value
strAddress = .Address
End With
Rw = Sheets("Log").Range("A" & Rows.Count).End(xlUp).Row + 1
With Sheets("Log")
.Cells(Rw, 1) = strAddress
.Cells(Rw, 2) = Me.Name 'Sheet Name
.Cells(Rw, 3) = Environ("UserName")
.Cells(Rw, 4) = dtmTime
.Cells(Rw, 5) = val
.Cells(Rw, 6) = ActiveWorkbook.FullNameURLEncoded 'Address of workbook at the time
End With
End Sub
现在,我还想在更改时跟踪“目标行”和“列A”的相交处的值,原因是要对工作表进行过滤并添加行,并知道“列”的值是多少A将标识更改的位置。
即在单元格B5中进行了更改,我需要A5的值。 Z98,A98等。