PDA

View Full Version : Solved: user name



Scooter172
02-26-2013, 07:52 AM
how do i have a cell in excel default value equal the user name of the computer?

JKwan
02-26-2013, 08:17 AM
try
MsgBox Environ("username")

Fett2oo5
02-26-2013, 08:45 AM
I am also looking for this but in an "auto-fill" capacity.
I have a form for the users to fill out if there is a problem on their project.
There is a: Problem column, and an Identified By column.
When the user enters text into the Problem column I would like for the corresponding cell to the right in the Identified By column to display their user name. This would be conditional, on if there is text in the problem column.

It would also be ideal if the current date could be entered in a cell to the right if text is entered in the Problem column.

I'm a VBA novice and very willing to learn, please be patient with my lack of experience.

snb
02-26-2013, 09:02 AM
Sub M_snb()
Cells(1) = CreateObject("wscript.network").computername
End Sub

Fett2oo5
02-26-2013, 09:52 AM
Thank you for the reply, however rather embarrassingly, I don't know where to place this code in the workbook for it to work.

.....

After looking around the site and some KB I found pieces of code I could use.
I have an issue log for users to fill out. When a user puts text into a cell, say C4. The date will autofill as well as the user's username in D4, and E4.

This is what I pieced together from various sources on this site:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)

' Get and insert the current date 1 cell right from entered text
With Target
If .Count > 1 Then Exit Sub
If Not Intersect(Range("C4:C1000 "), .Cells) Is Nothing Then
Application.EnableEvents = False
If IsEmpty(.Value) Then
.Offset(0, 1).ClearContents
Else
With .Offset(0, 1)
.NumberFormat = "mm/dd/yy"
.Value = Now
End With
End If
Application.EnableEvents = True
End If
End With

' Get and insert the username 2 cells right from entered text
With Target
If .Count > 1 Then Exit Sub
If Not Intersect(Range("C4:C1000 "), .Cells) Is Nothing Then
Application.EnableEvents = False
If IsEmpty(.Value) Then
.Offset(0, 2).ClearContents
Else
With .Offset(0, 2)
.Value = Application.UserName
End With
End If
Application.EnableEvents = True
End If
End With
End Sub

I'm not sure if this is the best way to go about this. Could a more experienced person take a look and see if I could have put this code together in a more efficient manner please?