我需要帮助编写一个代码,当在 I 中输入任何值时,该代码将允许在 H 列中使用日期/时间戳。现在,当在 B 列中输入值时,下面的代码允许在 G 中使用时间戳。我需要做什么?
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim rCell As Range
Dim rChange As Range
On Error GoTo ErrHandler
Set rChange = Intersect(Target, Range("B:B"))
If Not rChange Is Nothing Then
Application.EnableEvents = False
For Each rCell In rChange
If rCell > "" Then
With rCell.Offset(0, 5)
.Value = Now
.NumberFormat = "mm-dd-yy h:mm AM/PM"
End With
Else
rCell.Offset(0, 5).Clear
End If
Next
End If
ExitHandler:
Set rCell = Nothing
Set rChange = Nothing
Application.EnableEvents = True
Exit Sub
ErrHandler:
MsgBox Err.Description
Resume ExitHandler
End Sub