+ Reply to Thread
Results 1 to 15 of 15

Add Time & Date in current cell without losing existing data

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-14-2007
    MS-Off Ver
    Excel 2021
    Posts
    121

    Add Time & Date in current cell without losing existing data

    Trying to create a macro that will add the date & time & initials (i.e 8/26/09 2:34 PM JOD) into the current cell.

    I've found plenty of macro's that will do this but it ends up deleting any existing text within the cell. I need to be able to add it in the middle of a text string.

    Any help would be greatly appreciated

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Add Time & Date in current cell without losing existing data

    For example, ...
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor
    Join Date
    10-14-2007
    MS-Off Ver
    Excel 2021
    Posts
    121

    Re: Add Time & Date in current cell without losing existing data

    For example, the following macro will insert Date/Time into a field but it clears the contents of anything in the cell.

    Sub Set_DateTime()
    ActiveCell.Value = Format(Now(), "m/dd/yyyy h:mmAM/PM")
    End Sub

    This is an example of what my notes field would look like:
    8/26/09 2:33 PM JOC Tested Ok. 8/27/09 3:33 PM ABC Sent tech to regional.

    How can i automatically add 8/27/09 3:33 PM ABC without clearing the existing data in the cell?

    Thanks

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Add Time & Date in current cell without losing existing data

    Sub Set_DateTime()
        ActiveCell.Value = ActiveCell.Text & " " & Format(Now(), "m/dd/yyyy h:mmAM/PM")
    End Sub

  5. #5
    Forum Contributor
    Join Date
    10-14-2007
    MS-Off Ver
    Excel 2021
    Posts
    121

    Re: Add Time & Date in current cell without losing existing data

    Sorry for not putting the macro within a code. Still no luck with this one?

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Add Time & Date in current cell without losing existing data

    Pardon?

    Try the code I posted.

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Add Time & Date in current cell without losing existing data

        With ActiveCell
            .Font.Bold = False
            .Value = Format(Now(), "mm/dd/yy@hh:mm ") & .Text
            .Characters(1, 14).Font.Bold = True
        End With

  8. #8
    Registered User
    Join Date
    04-11-2013
    Location
    Boston, Massachusetts
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Add Time & Date in current cell without losing existing data

    Thank you shg! One issue I'm having is that when you enter this time stamp, it unbolds all previous stamps in the cell. Is it possible to not affect the pre-existing text format? Also, is it possible to push the old text down to the line below the new stamp, something similar to what I've pasted below? I have also included what my code currently looks like.

    "05/19/2014 (SM): Allocated.
    05/18/2014 (SM): Uploaded."


    Private Sub CommandButton1_Click()
    Dim MessageBox
    MessageBox = MsgBox(Prompt:="Add Comment?", Buttons:=vbYesNo)
    If MessageBox = vbYes Then
    With ActiveCell
        .Font.Bold = False
        .Value = Format(Now(), "mm/dd/yyyy") & " (SM):" & .Text
        .Characters(1, 15).Font.Bold = True
    End With
    If MessageBox = vbNo Then Exit Sub
    End If
    End Sub

  9. #9
    Registered User
    Join Date
    05-21-2014
    Posts
    1

    Re: Add Time & Date in current cell without losing existing data

    Thanks you so much!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1