GarethSteval
New Member
- Joined
- Jun 12, 2015
- Messages
- 4
Hi everyone
Long time lurker, here's my first post
I am struggling with code, I simply can't get this to work. I want to write a macro that when you complete editing text, it adds the date in brackets once you exit the cell. This is for an activity tracking list, so you type the comment and it should automatically insert the date that the comment was logged once enter is pressed.
This is the macro:
ActiveCell.Value = ActiveCell.Value & " [" & Date & "]"
I have tried the code in the following:
Private Sub Worksheet_Change
Self-explanatory
Private Sub Worksheet_SelectionChange
Self-explanatory
The problem is it only changes the cell that you click on, not the one that you were on.
I eventually got both the above to work by referring to the above cell (not the best method though), but they ended up putting the date a million times in one cell (obviously, when it adds the date, it recognises the change and runs it again). Als
Application.OnKey "{Enter}"
It wouldn't run when it was in edit mode (well, I think that's what the problem was)
I tried:
Private Sub PolNo_KeyPress(KeyAscii As Integer)
If (KeyAscii = 13) Then
Call DateMacro
End If
Range("A1").Value = KeyAscii
End Sub
It didn't work nor did it post the button pressed to A1.
I tried searches and I just can't seem to get this to work. Any help would be greatly appreciated. Thanks!
Long time lurker, here's my first post
I am struggling with code, I simply can't get this to work. I want to write a macro that when you complete editing text, it adds the date in brackets once you exit the cell. This is for an activity tracking list, so you type the comment and it should automatically insert the date that the comment was logged once enter is pressed.
This is the macro:
ActiveCell.Value = ActiveCell.Value & " [" & Date & "]"
I have tried the code in the following:
Private Sub Worksheet_Change
Self-explanatory
Private Sub Worksheet_SelectionChange
Self-explanatory
The problem is it only changes the cell that you click on, not the one that you were on.
I eventually got both the above to work by referring to the above cell (not the best method though), but they ended up putting the date a million times in one cell (obviously, when it adds the date, it recognises the change and runs it again). Als
Application.OnKey "{Enter}"
It wouldn't run when it was in edit mode (well, I think that's what the problem was)
I tried:
Private Sub PolNo_KeyPress(KeyAscii As Integer)
If (KeyAscii = 13) Then
Call DateMacro
End If
Range("A1").Value = KeyAscii
End Sub
It didn't work nor did it post the button pressed to A1.
I tried searches and I just can't seem to get this to work. Any help would be greatly appreciated. Thanks!