Username (multiple usage)

Spraggs

Well-known Member
Joined
Jan 19, 2007
Messages
704
Good evening,
I've got a table C2:N7 where employess enter data. I want to record the last person to fill in each cell by entering their username on another grid Q2:AB7. (i.e. C2 data, username entered in cell Q2 etc.)
Is this feasable? If so, how. e.g. what would the code be and where and how do I enter it. I'm using vista & excel 2007.

Any help is greatly appreciated.
Thanks Jase
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
- right click your sheet tab
- View Code
- copy and paste in the code below

hth

Dave

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rng1 As Range
    Dim rng2 As Range
    Set rng1 = Intersect(Target, Range([c2], [n7]))
    If rng1 Is Nothing Then Exit Sub
    Application.EnableEvents = False
    For Each rng2 In rng1.Cells
        rng1.Offset(0, 14) = Environ("username")
    Next
    Application.EnableEvents = True
End Sub
 
Upvote 0
Could I have help to advance on this....?

I've set up another two tables one to show date with an offset of 28. And another showing entry time, with an offset of 42. Do I need two more code entries or can it all be done in one?
Regards Jase
 
Upvote 0
I would reduce your code lines and the number of write operations in the sheet, and go for:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rng1 As Range
    Set rng1 = Intersect(Target, [c2:n7])
    If rng1 Is Nothing Then Exit Sub
    For i = 1 To 3
        rng1.Offset(, 14 * i) = Environ("username")
    Next
End Sub

Wigi
 
Upvote 0
Thanks Wigi, but how would this work with the date and time stamps with the offsets as quoted?

Regards Jase
 
Upvote 0
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rng1 As Range
    Set rng1 = Intersect(Target, [c2:n7])
    If rng1 Is Nothing Then Exit Sub
    For i = 1 To 3
        rng1.Offset(, 14 * i) = Choose(i, Environ("username"), date, time)
    Next
End Sub
 
Upvote 0
You should always disable events before writing new entries with Worksheet_Change to stop the code refiring ....

Cheers

Dave
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,754
Members
452,940
Latest member
rootytrip

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