Macro to Add Windows Username in Cell

Kickingkangaroos

New Member
Joined
Sep 2, 2009
Messages
46
Hi All,

I have done a search on here to try to find what I'm looking for, but have been unable to get exactly what I need.

I "manage" a spreadsheet which multiple users access and update. It has columns B - I which the users can update; it's not shared, so users must enter it one at a time and save each time.

What I would like to add is a formula/function/macro (whatever it needs to be), to add the Windows Username of whoever has just updated the spreadsheet - specifically column B.

I.e. - User 1 opens the spreadsheet, enters new information for Row 121 (just as an example). I want there to be a function in column J, which automatically adds the Windows Username for User 1 into J121.

Then when User 2 opens up the spreadsheet, and enters new data in Row 122; the function runs again to enter the Windows Username of User 2 in J122.

Etc etc...

So there is an historic record of who input each Row into the spreadsheet.

Can this be done at all?

Any help would be much appreciated, and please let me know if you need me to provide a clear explanation of what I am trying to achieve.

Many thanks,

Andy
 
For 1. try

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Target.Column = 2 Then
    Application.EnableEvents = False
    If Target.Value <> "" Then
        Target.Offset(, 8).Value = Environ("username")
    Else
        Target.Offset(, 8).ClearContents
    End If
    Application.EnableEvents = True
End If
End Sub

For 2, the user name will remain until a change is made to column B.

With this code is there a way to be able to have multiple column included instead of just 1 column and still have all the usernames show up in the same column.</SPAN>
 
Upvote 0

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
With this code is there a way to be able to have multiple column included instead of just 1 column and still have all the usernames show up in the same column.

Something like this

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Target.Column = 2 Or Target.Column = 5 Then
    Application.EnableEvents = False
    If Target.Value <> "" Then
        Range("A" & Target.Row).Value = Environ("username")
    Else
        Range("A" & Target.Row).ClearContents
    End If
    Application.EnableEvents = True
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,607
Messages
6,179,871
Members
452,949
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top