Cell input to call macro in adjacent cell

December 2016




Issue



I have a scenario that i'd like automated. The scenario is as follows

If i enter a value in any cell in a particular column, i want the system time to be entered in the adjacent cell. Currently i have used this command in a macro to do it, but it is a manual process (ActiveCell.Value = Time) and i have to click on the adjacent cell and then press the shortcut buttons to do it every time.


Example:

If i enter 123 in cell A2, then i want the system time (eg. 6:59:33 PM) to be captured in cell B2. I want to continue entering values in the column 'A' one below the other with system time being automatically entered down to the second in the corresponding adjacent cell in column 'B'. Is this possible, it would be awesome if someone could help me.

Solution


Implement this code on the worksheet you want it to work on (right click on the worksheet tab, click on view code):

Private Sub Worksheet_Change(ByVal Target As Range) 
ActiveCell.Offset(-1, 1) = Time 
End Sub


Whenever you put something in a cell and hit ENTER, the current system time is being put in the adjacent cell to the right.

Note


NOTE that you have to confirm your entry by hitting ENTER and not use the arrows or TAB.

Thanks to Trowa for this tip on the forum.

Related :

This document entitled « Cell input to call macro in adjacent cell » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.