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

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

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?
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,168,128
Messages
5,857,533
Members
431,884
Latest member
Gcmoore63

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
Top