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?
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?
Right-click on the sheet tab, select view code, and copy and paste the following:
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?![]()
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
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!
For a range of cells, you would need a little extra code:
You can change the red range above to suit your needs.![]()
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
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
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.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks