Auto insert username

Thanks Thanks:  0
Likes Likes:  0
Results 1 to 9 of 9

Thread: Auto insert username

  1. #1
    Board Regular
    Join Date
    Jul 2003
    Location
    San Francisco
    Posts
    112
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Auto insert username

     
    I need to be able to automatically insert user's username who made changes to the worksheet in a cell. Can you help how to do this.

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim I As Range
    Set I = Intersect(Range("C4:C500"), Target)

    If I Is Nothing Then Exit Sub
    Application.EnableEvents = False
    Dim c As Range
    For Each c In I
    c.Offset(0, 1).Value = "trigger the username of person in code"
    Next c
    Application.EnableEvents = True

    End Sub

  2. #2
    Board Regular
    Join Date
    May 2002
    Posts
    541
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Auto insert username

    Would Track Changes be suitable for your situation? When a cell is changed, its original value is saved along with the username, and a timestamp. This is accessed by going to Tools > Track Changes > Highlight Changes.

    Or you can access the username in your code with:

    Application.UserName
    <form action="http://www.google.com/search" name=f><input style="border:1px solid;" maxLength=256 size=15 name=q value=""> <input type=submit value="Search" name=btnG></form>

  3. #3
    MrExcel MVP
    Moderator
    Smitty's Avatar
    Join Date
    May 2003
    Location
    Redmond, WA
    Posts
    29,498
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    2 Thread(s)

    Default Re: Auto insert username

    Here's how to capture the current user name:

    Sub UserName()
    Dim CurrentUser As String
    CurrentUser = Environ("UserName")
    MsgBox CurrentUser
    End Sub


    Hope that helps,

    Smitty

  4. #4
    MrExcel MVP DRJ's Avatar
    Join Date
    Feb 2002
    Location
    California
    Posts
    3,853
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Code:
    c.Offset(0, 1).Value = Environ("USERNAME")

  5. #5
    Board Regular
    Join Date
    Jul 2003
    Location
    San Francisco
    Posts
    112
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Quote Originally Posted by DRJ
    Code:
    c.Offset(0, 1).Value = Environ("USERNAME")
    Woooo... Thanks, this works perfect...

  6. #6
    MrExcel MVP DRJ's Avatar
    Join Date
    Feb 2002
    Location
    California
    Posts
    3,853
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    You're Welcome

    Take Care

  7. #7
    Board Regular
    Join Date
    Jul 2003
    Location
    San Francisco
    Posts
    112
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi Jacob - thanks. I am not well on vba maybe you can help me with this one. Maybe using Case...? I Cant seem to get it done. Your help is really apprecicated. thanks.


    I need to be able to put dates automatically on VBA for cells using offset shown below. The sample is only for one column. How do I get these cells to update for using following offsets.
    Offsets:
    j = 11
    k = 1
    l = 30
    m = 4
    n = 1

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim I, j, k, l, m, n As Range
    Set I = Intersect(Range("BC4:BC500"), Target)
    Set j = Intersect(Range("AT4:AT500"), Target)
    Set k = Intersect(Range("AD4:AD500"), Target)
    Set l = Intersect(Range("AN4:AN500"), Target)
    Set m = Intersect(Range("AL4:AL500"), Target)
    Set n = Intersect(Range("AP4:AP500"), Target)

    If I Is Nothing Then Exit Sub
    Application.EnableEvents = False
    Dim c As Range
    For Each c In I
    c.Offset(0, 1).Value = Format(Now, "mm/dd/yy")
    Next c
    Application.EnableEvents = True

    End Sub

  8. #8
    Legend NateO's Avatar
    Join Date
    Feb 2002
    Location
    Minneapolis, Mn, USA
    Posts
    9,700
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Auto insert username

    See your original thread regarding your latest request.

    http://www.mrexcel.com/board2/viewtopic.php?t=88069

  9. #9
    Board Regular
    Join Date
    Dec 2010
    Location
    Dallas, TX
    Posts
    73
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Auto insert username

      
    I tried using this code but couldn't get it to work for me. I need this to look in column E & F and add the username in column W of the same row if a change was made in column E or F. Column E & F will start out blank, and the username only needs to be added if they add something to one of those columns. If possible it would also be nice to add a date and time stamp to column X. Any help is appreciated.

    Code:
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim I As Range
    Set I = Intersect(Range("E2:F1000"), Target)
    If I Is Nothing Then Exit Sub
    Application.EnableEvents = False
    Dim c As Range
    For Each c In I
    c.Offset(0, 17).Value = Environ("USERNAME")
    Next c
    Application.EnableEvents = True
    End Sub
    Last edited by julia55; Oct 27th, 2011 at 12:10 PM.

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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

 

 
DMCA.com