+ Reply to Thread
Results 1 to 10 of 10

Auto Inserting MS Office Username on Event Change

Hybrid View

  1. #1
    Registered User
    Join Date
    05-06-2005
    Posts
    30

    Auto Inserting MS Office Username on Event Change

    I have a shared spreadsheet that uses a column with a validation list. I want to be able to take the MS Office Username contained in Tools > Options to be put into a cell A1 when changing the value of A2.

    Is it possible?

  2. #2
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    Right-click on the sheet tab, select view code, and copy and paste the following:
    Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
        Set Target = Cells(2, 1)
        Cells(1, 1).Value = ""
        If Target.Value <> "" Then Cells(1, 1).Value = Application.UserName
    End Sub
    This will enter the MS Excel user name in cell A1 whenever cell B1 is anything except blank. Is this what you were looking for?

  3. #3
    Registered User
    Join Date
    05-06-2005
    Posts
    30
    Will this work for the range of a column or is it cell specific? Other than that, it's exactly what I was inquiring about. Thanks!

  4. #4
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    For a range of cells, you would need a little extra code:
    Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
        Dim rng As Range
        Set Target = Range("A2:A10")
        Cells(1, 1).Value = ""
        For Each rng In Target
            If rng.Value <> "" Then
            Cells(1, 1).Value = Application.UserName
            End If
        Next rng
    End Sub
    You can change the red range above to suit your needs.

  5. #5
    Registered User
    Join Date
    05-06-2005
    Posts
    30
    Thanks again. I tried the code and it works, but puts the value in a singular specific field. I don't think I'm explaining myself correctly.

    For every cell in the range (let's say A3:A1501) that changes to Y, I need the corresponding cell in B3:B1501 to change to the username.

    thanks again

  6. #6
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    After playing around with code for a while and wondering why I couldn't get it to work, I realized I was using the SelectionChange event, rather than the Change event. OOPS! This code should work for you hopefully:
    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
        Dim rng As Range
        Set rng = [B3:B1501]
        If Intersect(Target, rng) Is Nothing Then Exit Sub
        Target.Offset(0, -1).Value = ""
        Target.Offset(0, -1).Value = Application.UserName
    End Sub
    Last edited by jasoncw; 01-25-2007 at 06:54 PM.

+ 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