Link to home
Start Free TrialLog in
Avatar of Taras
TarasFlag for Canada

asked on

excel concatenate text to date time stamp

I am using this code to put time stamp in cell B5:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range

    ' The variable KeyCells contains the cells that will
    ' cause an alert when they are changed.

    With Me
        Set KeyCells = .Range("D5")
   
        If Not Application.Intersect(KeyCells, Target) Is Nothing Then
   
            ' we will put time stamp in cell B5
            Application.EnableEvents = False
            .Cells(5, "B").Value = Now()
            .Cells(5, "B").NumberFormat = "m/d/yyyy h:mm AM/PM"
            Application.EnableEvents = True
        End If

    End With

End Sub

It works ok however I need to concatenate  "Run at: "  to this time stamp.
Any idea.
ASKER CERTIFIED SOLUTION
Avatar of byundt
byundt
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Replace the lines
 .Cells(5, "B").Value = Now()
 .Cells(5, "B").NumberFormat = "m/d/yyyy h:mm AM/PM"

Open in new window


With:
.Cells(5, "B").Value = "Run at: " & Format(Now(), "m/d/yyyy h:mm AM/PM")

Open in new window

Avatar of Taras

ASKER

Thank you a lot.