another get username question

echobravo

New Member
Joined
Dec 18, 2014
Messages
4
hello.
sorry for another get the username question but i didnt want to revive any old posts, however i will reference them cause maybe its something im doing wrong and not the code.

http://www.mrexcel.com/forum/excel-questions/552014-macro-add-windows-username-cell.html
in this post im trying to do the same thing.
i want the username to appear in a cell of my choosing when the user saves the file.
if another user open and saves the file i want their username to appear in a cell, in the row below the the last user to save the file.
i dont want the previous users name to be overwritten with the current users name.

i tried the code in the above linked post but im not having success in getting it to work.

can anyone help me out with this

i appreciate your time and help
 
i can't help with the code but can offer how i would look at doing this

i would create a file save button to this i would first add the current user name to the field i wanted last saved by and then save and close workbook

on opening the work book i would populate the current user field with current user name

sorry not a solution but might help others help you
 
Upvote 0
hello.
sorry for another get the username question but i didnt want to revive any old posts, however i will reference them cause maybe its something im doing wrong and not the code.

http://www.mrexcel.com/forum/excel-questions/552014-macro-add-windows-username-cell.html
in this post im trying to do the same thing.
A quick look at that thread shows several messages with code in them... which one did you want to use a the starting point for the functionality you are seeking?
 
Upvote 0
A quick look at that thread shows several messages with code in them... which one did you want to use a the starting point for the functionality you are seeking?
i tried this code
like most code ive tried they all had a =username() type of function to put in the cell.
im affraid i dont understand enough of this code to get this to work properly.

thanks for your replies

Code:
Private Sub Worksheet_Change(ByVal Target As Range)If Target.Count > 1 Then Exit SubIf Target.Column = 2 Then    Application.EnableEvents = False    Target.Offset(, 8).Value = Environ("username")    Application.EnableEvents = TrueEnd IfEnd Sub
</pre>
 
Upvote 0
i tried this code
like most code ive tried they all had a =username() type of function to put in the cell.
im affraid i dont understand enough of this code to get this to work properly.

thanks for your replies

Code:
Private Sub Worksheet_Change(ByVal Target As Range)If Target.Count > 1 Then Exit SubIf Target.Column = 2 Then    Application.EnableEvents = False    Target.Offset(, 8).Value = Environ("username")    Application.EnableEvents = TrueEnd IfEnd Sub
The code you referenced is not a UDF (user defined function) which would have been use like you showed; rather, it is event code which works automatically when (for what you posted) a cell in Column 2 is changed. Here is that code revised to function the way you asked...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Count > 1 Then Exit Sub
  If Target.Column = 2 Then
    Application.EnableEvents = False
    Cells(Rows.Count, Target.Offset(, 8).Column).End(xlUp).Offset(1).Value = Environ("username")
    Application.EnableEvents = True
  End If
End Sub

Note: Event code is installed in a Sheet Module, not a General Module (which is where macros and UDFs are installed). See below for general installation instructions...


HOW TO INSTALL Event Code
------------------------------------
If you are new to event code procedures, they are easy to install. To install it, right-click the name tab at the bottom of the worksheet that is to have the functionality to be provided by the event code and select "View Code" from the popup menu that appears. This will open up the code window for that worksheet. Copy/Paste the event code into that code window. That's it... the code will now operate automatically when its particular event procedure is raised by an action you take on the worksheet itself. Note... if you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.
 
Upvote 0
The code you referenced is not a UDF (user defined function) which would have been use like you showed; rather, it is event code which works automatically when (for what you posted) a cell in Column 2 is changed. Here is that code revised to function the way you asked...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Count > 1 Then Exit Sub
  If Target.Column = 2 Then
    Application.EnableEvents = False
    Cells(Rows.Count, Target.Offset(, 8).Column).End(xlUp).Offset(1).Value = Environ("username")
    Application.EnableEvents = True
  End If
End Sub

Note: Event code is installed in a Sheet Module, not a General Module (which is where macros and UDFs are installed). See below for general installation instructions...


HOW TO INSTALL Event Code
------------------------------------
If you are new to event code procedures, they are easy to install. To install it, right-click the name tab at the bottom of the worksheet that is to have the functionality to be provided by the event code and select "View Code" from the popup menu that appears. This will open up the code window for that worksheet. Copy/Paste the event code into that code window. That's it... the code will now operate automatically when its particular event procedure is raised by an action you take on the worksheet itself. Note... if you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.


thank you for your help.
how does this work exactly?
what cell would the username appear in?
i tried typing something in each cell in row A but nothing is showing
 
Upvote 0
got it working... i never saved it as an .xlsm worked after i did that.

thank you very much for your help
have a merry christmas
 
Upvote 0
thank you for your help.
how does this work exactly?
what cell would the username appear in?
i tried typing something in each cell in row A but nothing is showing

The code you quoted as having tried originally had this line in it...

Code:
If Target.[COLOR=#FF0000][B]Column[/B][/COLOR] = [COLOR=#FF0000][B]2[/B][/COLOR] Then

which monitors column #2 (which is Column B), so I used that same condition in my code. If you want to monitor Column A, change the 2 to 1.
 
Upvote 0

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