Insert Date Time Stamp with VBA

In case you want a VBA code to automatically record date & time stamp in a specific cell & insert date & time stamp based on the changes in other cell, then this article is for you.

In this article, we will learn how to insert Date & Time Stamp, using vba coding.

 

Question): I want to add date & time stamp in cell B2 through vba code when I enter anything in cell A2.

In order to get date & time stamp, using vba code, we need to follow the below steps to launch VB editor

  • Click on Developer tab
  • From Code group, select Visual Basic

 

img1

 

  • Copy the below code in Worksheet module

 

Private Sub Worksheet_Change(ByVal Target As Range)

  If Target.Column = 1 And Target.Row = 2 Then

    If Target.Value = “” Then

      Cells(2, 2).Value = “”

    Else

      Cells(2, 2).Value = Format(Now, “mm/dd/yyyy HH:mm:ss”)

    End If

  End If

End Sub

 

 

 

img2

 

  • As we enter anything in cell A2; the corresponding cell B2 will get date & time stamp automatically as we are using Worksheet Change event. Refer below snapshot

 

img3

 

  • If we delete value in cell A2 then date & time stamp will also be deleted.

In this way, we can insert date & time stamp using vba in Microsoft Excel 2010.

 

Excel

Download – Insert Date Time Stamp with VBA – xlsm

Users are saying about us...

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Terms and Conditions of use

The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.

Visit Us On TwitterVisit Us On FacebookVisit Us On Google PlusVisit Us On Youtube