Autoinsert Username

hakuna

New Member
Joined
Sep 2, 2012
Messages
33
Hi,

I am new to excel. While searching for help on codes and different ways to simplify my task i came across this forum.
would be glad if someone could help me with my problem.

I have a huge excel sheet with data more than 100s of rows. it's a common workbook shared by evryone in my company. so everyone has access to it.

I need to define a code / macro to assign the username automatically as and when the user is identified without using the function manually. is this possible?

Something similar to a datestamp which automatically gets inserted.

URGENT help required.

Thanks in advance. :)
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
"...macro to assign the username automatically"

What do you want to "assign" it to? The following example will log the user name and the time and date they opened the workbook. You can modify for your needs.

Code:
Private Sub Workbook_Open()
Dim lngLastRow As Long
    
    lngLastRow = Sheet1.Cells(Rows.Count, "A").End(xlUp).Row
    Range("A" & lngLastRow + 1).Value = Application.UserName
    Range("B" & lngLastRow + 1).Value = Now()
End Sub
 
Upvote 0
Hello. I need help!
when i use the code, it is fine. but when i update the sheet, my username is getting displayed on every cell!
 
Upvote 0
What code are you actually using?
 
Upvote 0
Hi,

I am new to excel. While searching for help on codes and different ways to simplify my task i came across this forum.
would be glad if someone could help me with my problem.

I have a huge excel sheet with data more than 100s of rows. it's a common workbook shared by evryone in my company. so everyone has access to it.

I need to define a code / macro to assign the username automatically as and when the user is identified without using the function manually. is this possible?

Something similar to a datestamp which automatically gets inserted.

URGENT help required.

Thanks in advance. :)

I would do something like this.

Basically if anyone wants to insert a new row of data to press a button which will automatically put in the date and their username.

Sub NewRow()

Dim MyName As String
Dim r As Integer
' latest info finder
'move to new row and +1
Range("F3").End(xlDown).Offset(1, 0).Select <----------------Input the first cell with a list of information (key field, in the case of this example, F3 contains the first of a list of primary keys)
r = ActiveCell.Row
'add initials
MyName = Environ("username")
Range("J" & r).Value = MyName <------------input the column letter you want the name put into (J)
'add date
Range("G" & r).Value = Date <-------------------input the column letter you want the date pasted into (G)
Range("K" & r).Select <------------------------- this will select the first cell where you would like them to start inputting information

End Sub
 
Last edited:
Upvote 0
What code are you actually using?

the code I am using is different but it produces username. :confused:

this is my code:

if activecell.value = "sent" and .offset(0,13) = "" then
activecell.offset(0,13) = application.username
end if

This is a case when it is "sent" i have 2 other cases too.

When I enter something in that cell, my USERNAME is produced in the X column. However, after saving the file on exit, and when I re-open it, and UPDATE, the entire X Column has my USERNAME!!! :nya:

PLease kindly help!
 
Upvote 0
I would do something like this.

Basically if anyone wants to insert a new row of data to press a button which will automatically put in the date and their username.

Sub NewRow()

Dim MyName As String
Dim r As Integer
' latest info finder
'move to new row and +1
Range("F3").End(xlDown).Offset(1, 0).Select <----------------Input the first cell with a list of information (key field, in the case of this example, F3 contains the first of a list of primary keys)
r = ActiveCell.Row
'add initials
MyName = Environ("username")
Range("J" & r).Value = MyName <------------input the column letter you want the name put into (J)
'add date
Range("G" & r).Value = Date <-------------------input the column letter you want the date pasted into (G)
Range("K" & r).Select <------------------------- this will select the first cell where you would like them to start inputting information

End Sub


Thanks for the help. But i don't have to insert USERNAME on every new row entry.

When I randomly enter data in between rows, it must produce USERNAME in a separate column X. and this is permanent.

I hope you are getting what I am trying to say ???!!
 
Upvote 0
How is your code being triggered? I would hazard a guess it's in an event routine, but which one?
 
Upvote 0
How is your code being triggered? I would hazard a guess it's in an event routine, but which one?

I'm not understanding what you've asked...

This is part of the code in a sheet.

Private Sub Worksheet_Change(ByVal as Target excel.range)
Application.enableevents = false
On error goto enditall
IF Target = column(11) //// target is set to column 11

with target
If .value = "sent" and .offset(0,13) = "" then
.offset(0,13).value = APPLICATION.USERNAME
end if
end with

With ....
IF....

end if
end with

with ...
if...

end if...
end with...

end if

enditall:
application.enableevents = true


This is the code I'm using now.
Please guide me!
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,250
Members
452,623
Latest member
Techenthusiast

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