Auto insert username

maxlm

Board Regular
Joined
Jul 22, 2003
Messages
112
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
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
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
 
Upvote 0
Here's how to capture the current user name:

<font face=Tahoma><SPAN style="color:#00007F">Sub</SPAN> UserName()
    <SPAN style="color:#00007F">Dim</SPAN> CurrentUser <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
        CurrentUser = Environ("UserName")
        MsgBox CurrentUser
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>

Hope that helps,

Smitty
 
Upvote 0
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
 
Upvote 0
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:
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

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