Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count = 1 Then
If Target.Column = 4 Then
Cells(Target.Row, 6) = Now
End If
End If
End Sub
这是我在网上收的,日期的格式太详细,我想只显示月、日就可以了。右键单元格,设置单元格格式不行,能否在vba中就把日期的格式定义好。
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count = 1 Then
If Target.Column = 4 Then
Cells(Target.Row, 6).NumberFormatLocal = "yyyy-m-d" '年月日
'Cells(Target.Row, 6).NumberFormatLocal = "m-d" '月日
Cells(Target.Row, 6) = Now
End If
End If
End Sub