+ Reply to Thread
Results 1 to 6 of 6

How to get time stamp and user name stamp

  1. #1
    Registered User
    Join Date
    06-06-2013
    Location
    Wausau, WI
    MS-Off Ver
    Excel 2010
    Posts
    3

    Question How to get time stamp and user name stamp

    I have written the following code:
    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    With Target
    If .Count > 1 Then Exit Sub
    If Not Intersect(Range("C7:F20"), .Cells) Is Nothing Then
    Application.EnableEvents = False
    If IsEmpty(.Value) Then
    .Offset(0, 0).ClearContents
    Else
    With .Offset(0, 0)
    .NumberFormat = "mmm dd yyyy hh:mm:ss"
    .Value = Now
    End With
    End If
    Application.EnableEvents = True
    End If
    End With
    End Sub


    I am using this code to create time sheets in excel. I have created the sheet with Four columns.
    Column "C" is used to "log in"". All the user has to do is place an "X" in the cell, and I have it autopopulating with the date and time.

    Column "D" is used to "log out for lunch". Again, all the user has to do is place an "X" in the cell, and it will autopopulate with the current date and time.

    Column "E" is used to "log in after lunch". Again, all the user has to do is place an "X" in the cell, and it will autopopulate with the current date and time.

    Column "F" is used to "log out". Again, all the user has to do is place an "X" in the cell, and it will autopopulate with the current date and time.

    I would actually like to add a column between "C" and "D" which will show the user name of the person that "logged in". This will ultimately make column "D" which is used to "log out for lunch" change and become column "E". I would then like to add column "F" to show the user name of the person that "logged out for lunch" and so on for the other two columns.

    I can't figure out how to change my code to accomodate this. I'm completely new to this, and am impressed that I have gotten this far as I am completely "self taught" when it comes to Excel, but any help that I could get would be most appreciated. I'm hoping this all makes sense.

    Thanks, LS

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: How to get time stamp and user name stamp

    Please Login or Register  to view this content.
    will give you the username of the current user.

  3. #3
    Registered User
    Join Date
    06-06-2013
    Location
    Wausau, WI
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: How to get time stamp and user name stamp

    Yes, it should be the user that keyed the "X" in the previous cell. This is our safety net so that one employee can't email their time sheet for another employee to update on their behalf, because if they do, it will show their user name instead of the employee to which the time sheet belongs.

  4. #4
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,576

    Re: How to get time stamp and user name stamp

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code in [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

  5. #5
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: How to get time stamp and user name stamp

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    06-06-2013
    Location
    Wausau, WI
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: How to get time stamp and user name stamp

    yudlugar, Thank you, it works great!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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