Current Username into a cell

alexg

New Member
Joined
Sep 25, 2006
Messages
4
I Am Generating a spreadsheet and need to use the current logged in username as a Variable quantity in a lookup - Does anyone know how i can get the curretn log in users username to appear in a cell in excel??

Kind reagrds

Alex
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
VB

were would I enter this code and in what context would i use it to make the anwser apear in a specific cell??
 
Upvote 0
Im Trying to get the username into cell D1 and enter the code as follows why is it not working - I feel i am somewhat out my depth here

Option Explicit
CURRENT_USER = Environ("UserName")
Private Sub Worksheet(ByVal Target As Range)
If [D1] = "" Then
[D1].Value = Environ("UserName")
Else
Cells(Rows.Count, "D").End(xlUp)(2, 1).Value = Environ("UserName")
End If
End If
End Sub
 
Upvote 0
I tried the code from the other thread and mine is not working too:

Code:
Private oldData 

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range) 
Dim i As Long, ii As Long 
If Sh.Name = "secret" Then Exit Sub 
Application.EnableEvents = False 
If Not IsArray(oldData) Then 
    If oldData <> Target.Value Then 
        Sheets("secret").Cells(Rows.Count, "a").End(xlUp).Offset(1) = _ 
        Application.UserName 
    End If 
Else 
    For i = 1 To UBound(oldData, 1) 
        For ii = 1 To UBound(oldData, 2) 
            If Target.Cells(i, ii) <> oldData(i, ii) Then 
                Sheets("secret").Cells(Rows.Count, "a").End(xlUp).Offset(1) = _ 
                Application.UserName 
                Exit For 
            End If 
        Next 
    Next 
End If 
Application.EnableEvents = True 
End Sub 

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range) 
oldData = Target.Value 
End Sub
 
Upvote 0
Hello,

try thic code in the THIS WORKBOOK code window

Code:
Private Sub Workbook_Open()
    If [D1] = "" Then
        [D1].Value = Environ("UserName")
    Else
        Cells(Rows.Count, "D").End(xlUp)(2, 1).Value = Environ("UserName")
    End If
End Sub
 
Upvote 0
Hello,

try thic code in the THIS WORKBOOK code window

Code:
Private Sub Workbook_Open()
    If [D1] = "" Then
        [D1].Value = Environ("UserName")
    Else
        Cells(Rows.Count, "D").End(xlUp)(2, 1).Value = Environ("UserName")
    End If
End Sub

Quick Hijack as this intrigues me - Works a treat, except my name is displayed as mandrews - Excel is set to Mark Andrews?
 
Upvote 0
Hello,

i think, and correct me if i'm wrong, nut it comes from the PC not excelas such, we use xp and on a network and my login name is the same as =environ(username).
 
Upvote 0
Hi,

I have entered this into mywrkbook and it still does not give me my username...

Any ideas why?
 
Upvote 0

Forum statistics

Threads
1,214,815
Messages
6,121,715
Members
449,049
Latest member
THMarana

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