|
如下建立在EXCEL中的一段代码,用来监控Excel中单元格修改的变化,每一个单元格发生变化都会有记录,问题来了:
如果我修改了某一单元格里面的数据两次及以上,我如何只让下面代码生成的日志中保存最后修改的那次操作,之前的那些操作就不做记录。
Dim XX
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal target As Range)
On Error Resume Next
If Sh.Name <> "日志" And target.Rows.Count = 1 Then
With Sheets("日志")
If XX <> target Then
ROW1 = Sheets("日志").[A65536].End(xlUp).Row + 1
.Cells(ROW1, 1) = Format(Now, "yyyy-mm-dd hh:mm:ss")
.Cells(ROW1, 2) = Sh.Name
.Cells(ROW1, 3) = XX
.Cells(ROW1, 4) = target.Value
.Cells(ROW1, 5) = target.Address
.Cells(ROW1, 6) = Sheets("编辑区").[a2]
End If
End With
End If
End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal target As Range)
XX = target.Value
End Sub
|
|