+ Reply to Thread
Results 1 to 2 of 2

Auto insert date, time & user in columns when data is entered in another column?

Hybrid View

  1. #1
    Registered User
    Join Date
    05-16-2007
    Posts
    1

    Question Auto insert date, time & user in columns when data is entered in another column?

    I have been looking for a macro that will automatically insert the date in column a, time in column b, and userid in column c, when date is entered into column d. Can someone help me write this? I would greatly appreciate it. I believe it is a Workbook_Change Event but I am having trouble writing the code to reflect the variables involved. Any input would be greatly appreciated. Thanks!
    SHEL

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    This might work

    Right click sheet name. Then Select view code and paste in th below

    Private Declare Function apiGetUserName Lib "advapi32.dll" _
        Alias "GetUserNameA" (ByVal lpBuffer As String, nsize As Long) As Long
    
    
    Function fOSUserName() As String
    ' Returns the network login name
    Dim lngLen As Long, lngX As Long
    Dim strUserName As String
        strUserName = String$(254, 0)
        lngLen = 255
        lngX = apiGetUserName(strUserName, lngLen)
        If lngX <> 0 Then
            fOSUserName = Left$(strUserName, lngLen - 1)
        Else
            fOSUserName = ""
        End If
    End Function
    
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    If IsDate(Target) = True Then
    If Target.Column = 4 Then
    ActiveCell.Offset(-1, -3).Value = Date
    ActiveCell.Offset(-1, -2).Value = Time
    ActiveCell.Offset(-1, -1).Value = fOSUserName
    End If
    End If
    End Sub
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

+ 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