Have a workbook that has multiple worksheets in it that are same design. Have two issues related to same code am looking for some assistance with.
1) The code below works well for generating date & time stamp.
There is one problem with the code. If an operator selects mutiple data entry cells & chooses delete. The date and time stamps do not clear as they should. if one cell is deleted works fine. Assistance with code appreciated.
2) With same code, am trying to apply worksheet_Change to many worksheets. Would like to set up one module with code in it & for each sheet simply Call The code in the Worksheet change. In this way when changes are made to the code it updates for all work sheets. If anyone is able to assist in altering code so this is possible & provide anything required in the worksheet change call code, would be appreciated.
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If .Count > 1 Then Exit Sub
If Not Intersect(Range("A29:A53"), .Cells) Is Nothing Then
Application.EnableEvents = False
If IsEmpty(.Value) Then
Cells(.Row, "F").ClearContents
Else
With Cells(.Row, "F")
NumberFormat = "dd mmm yyyy hh:mm:ss"
.Value = Now
End With
End If
Application.EnableEvents = True
End If
End With
With Target
If .Count > 1 Then Exit Sub
If Not Intersect(Range("b29:b53"), .Cells) Is Nothing Then
Application.EnableEvents = False
If IsEmpty(.Value) Then
Cells(.Row, "g").ClearContents
Else
With Cells(.Row, "g")
NumberFormat = "dd mmm yyyy hh:mm:ss"
.Value = Now
End With
End If
Application.EnableEvents = True
End If
End With
With Target
If .Count > 1 Then Exit Sub
If Not Intersect(Range("d29:d38"), .Cells) Is Nothing Then
Application.EnableEvents = False
If IsEmpty(.Value) Then
Cells(.Row, "h").ClearContents
Else
With Cells(.Row, "h")
NumberFormat = "dd mmm yyyy hh:mm:ss"
.Value = Now
End With
End If
Application.EnableEvents = True
End If
End With
With Target
If .Count > 1 Then Exit Sub
If Not Intersect(Range("d41:d45"), .Cells) Is Nothing Then
Application.EnableEvents = False
If IsEmpty(.Value) Then
Cells(.Row, "I").ClearContents
Else
With Cells(.Row, "I")
NumberFormat = "dd mmm yyyy hh:mm:ss"
.Value = Now
End With
End If
Application.EnableEvents = True
End If
End With
End Sub
1) The code below works well for generating date & time stamp.
There is one problem with the code. If an operator selects mutiple data entry cells & chooses delete. The date and time stamps do not clear as they should. if one cell is deleted works fine. Assistance with code appreciated.
2) With same code, am trying to apply worksheet_Change to many worksheets. Would like to set up one module with code in it & for each sheet simply Call The code in the Worksheet change. In this way when changes are made to the code it updates for all work sheets. If anyone is able to assist in altering code so this is possible & provide anything required in the worksheet change call code, would be appreciated.
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If .Count > 1 Then Exit Sub
If Not Intersect(Range("A29:A53"), .Cells) Is Nothing Then
Application.EnableEvents = False
If IsEmpty(.Value) Then
Cells(.Row, "F").ClearContents
Else
With Cells(.Row, "F")
NumberFormat = "dd mmm yyyy hh:mm:ss"
.Value = Now
End With
End If
Application.EnableEvents = True
End If
End With
With Target
If .Count > 1 Then Exit Sub
If Not Intersect(Range("b29:b53"), .Cells) Is Nothing Then
Application.EnableEvents = False
If IsEmpty(.Value) Then
Cells(.Row, "g").ClearContents
Else
With Cells(.Row, "g")
NumberFormat = "dd mmm yyyy hh:mm:ss"
.Value = Now
End With
End If
Application.EnableEvents = True
End If
End With
With Target
If .Count > 1 Then Exit Sub
If Not Intersect(Range("d29:d38"), .Cells) Is Nothing Then
Application.EnableEvents = False
If IsEmpty(.Value) Then
Cells(.Row, "h").ClearContents
Else
With Cells(.Row, "h")
NumberFormat = "dd mmm yyyy hh:mm:ss"
.Value = Now
End With
End If
Application.EnableEvents = True
End If
End With
With Target
If .Count > 1 Then Exit Sub
If Not Intersect(Range("d41:d45"), .Cells) Is Nothing Then
Application.EnableEvents = False
If IsEmpty(.Value) Then
Cells(.Row, "I").ClearContents
Else
With Cells(.Row, "I")
NumberFormat = "dd mmm yyyy hh:mm:ss"
.Value = Now
End With
End If
Application.EnableEvents = True
End If
End With
End Sub