I am attempting to have today's date automatically entered into the adjacent cell when data is entered in the cell. I used this code and it works in one spread sheet.
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If .Count > 1 Then Exit Sub
If Not Intersect(Range("A3:A200"), .Cells) Is Nothing Then
Application.EnableEvents = False
With .Offset(0, 1)
.NumberFormat = "MM/dd/yy hh:mm:ss"
.Value = Now
End With
Application.EnableEvents = True
End If
End With
End Sub
When I copy it to a new spreadsheet, it fails with Runtime error -1004
Unable to set the NumberFormat property of the Range class.
Why would it work in one spreadsheet and not the other?
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If .Count > 1 Then Exit Sub
If Not Intersect(Range("A3:A200"), .Cells) Is Nothing Then
Application.EnableEvents = False
With .Offset(0, 1)
.NumberFormat = "MM/dd/yy hh:mm:ss"
.Value = Now
End With
Application.EnableEvents = True
End If
End With
End Sub
When I copy it to a new spreadsheet, it fails with Runtime error -1004
Unable to set the NumberFormat property of the Range class.
Why would it work in one spreadsheet and not the other?