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
 

Some videos you may like

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

alexg

New Member
Joined
Sep 25, 2006
Messages
4
VB

were would I enter this code and in what context would i use it to make the anwser apear in a specific cell??
 

alexg

New Member
Joined
Sep 25, 2006
Messages
4

ADVERTISEMENT

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
 

bsnapool

Active Member
Joined
Jul 10, 2006
Messages
452
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
 

onlyadrafter

Well-known Member
Joined
Aug 19, 2003
Messages
5,703
Platform
  1. Windows

ADVERTISEMENT

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
 

MarkAndrews

Well-known Member
Joined
May 2, 2006
Messages
1,963
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?
 

onlyadrafter

Well-known Member
Joined
Aug 19, 2003
Messages
5,703
Platform
  1. Windows
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).
 

bsnapool

Active Member
Joined
Jul 10, 2006
Messages
452
Hi,

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

Any ideas why?
 

Watch MrExcel Video

Forum statistics

Threads
1,114,384
Messages
5,547,638
Members
410,805
Latest member
Ginoji
Top