Hi all,
I have a spreadsheet whereby anything entered into a cell between B2:B5000 it then would update the relevent row on columns C and D with both Username and Timestamp.
Now that bit works fine, however if they enter something into B2 and press Enter or Down, it will put the username and timestamp into C3 and D3
this is because it uses the activecell to judge where to put the username and timestamp
so my solution to this (which may very well be more complicated than it needs to be) was to do some if statements for the following
if down arrow is pressed then.. select target cell, move to the right, input username, move to the right, input timestamp and then do orignally selected down arrow to put the user on the cell they requested
Please see my code below and advise whats wrong with it
thanks in advance
I have a spreadsheet whereby anything entered into a cell between B2:B5000 it then would update the relevent row on columns C and D with both Username and Timestamp.
Now that bit works fine, however if they enter something into B2 and press Enter or Down, it will put the username and timestamp into C3 and D3
this is because it uses the activecell to judge where to put the username and timestamp
so my solution to this (which may very well be more complicated than it needs to be) was to do some if statements for the following
if down arrow is pressed then.. select target cell, move to the right, input username, move to the right, input timestamp and then do orignally selected down arrow to put the user on the cell they requested
Please see my code below and advise whats wrong with it
thanks in advance
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
If Not Intersect(Target, Range("B1:B5000")) Is Nothing Then
On Error Resume Next
If KeyAscii = 13 Then
Application.EnableEvents = False
Target.Cells.Select
ActiveCell.Offset(0, 1) = Application.UserName
ActiveCell.Offset(0, 2).Value = Now
Application.EnableEvents = True
ActiveCell.Offset(1, 0).Select
ElseIf KeyAscii = 37 Then
Application.EnableEvents = False
Target.Cells.Select
ActiveCell.Offset(0, 1) = Application.UserName
ActiveCell.Offset(0, 2).Value = Now
Application.EnableEvents = True
ActiveCell.Offset(0, -1).Select
ElseIf KeyAscii = 38 Then
Application.EnableEvents = False
Target.Cells.Select
ActiveCell.Offset(0, 1) = Application.UserName
ActiveCell.Offset(0, 2).Value = Now
Application.EnableEvents = True
ActiveCell.Offset(-1, 0).Select
ElseIf KeyAscii = 39 Then
Application.EnableEvents = False
Target.Cells.Select
ActiveCell.Offset(0, 1) = Application.UserName
ActiveCell.Offset(0, 2).Value = Now
Application.EnableEvents = True
ActiveCell.Offset(0, 1).Select
ElseIf KeyAscii = 40 Then
Application.EnableEvents = False
Target.Cells.Select
ActiveCell.Offset(0, 1) = Application.UserName
ActiveCell.Offset(0, 2).Value = Now
Application.EnableEvents = True
ActiveCell.Offset(1, 0).Select
On Error GoTo 0
End If
End If
End Sub