excel单元格记录修改时间 ps:vba循环判断或公式

2024-12-20 21:16:47
推荐回答(3个)
回答1:

Public b As Integer
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Column < 4 Or Target.Column > 12 Then Exit Sub
If b > 0 Then Exit Sub
a = Target.Row: b = Target.Column + 1
Cells(a, b) = Now
End Sub

代码写在工作簿ThisWorkbook模块中,这个代码不管你在哪个工作表修改数据都会产生效果,希望能帮助你

回答2:

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Column > 4 And Target.Column < 12 And Target.Column Mod 2 = 1 Then Target.Offset(, 1) = Now
End Sub
写到thisworkbook
如果你用
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column > 4 And Target.Column < 12 And Target.Column Mod 2 = 1 Then Target.Offset(, 1) = Now
End Sub
只能在代码当前sheet中发生事件

回答3:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 5 Or Target.Column = 7 Or Target.Column = 9 Or Target.Column = 11 Then
Target.Offset(, 1) = Now

End If

End Sub