Username ()

jamesmev

Board Regular
Joined
Apr 9, 2015
Messages
233
Office Version
  1. 365
Platform
  1. Windows
I am using the above to place the users information within the sheet. However, I have many sheets within my workbook and unless the actively click on the cell it doesn't populate that cell. Is there a VBA or macro that will engage this on all sheets updating all fields with Username() to that user without extra steps?

thank you
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
you might consider worksheet_activate, and then use Environ for your target cell, then it will always be right for the relevant user (unless they disable macros)
 
Upvote 0
you might consider worksheet_activate, and then use Environ for your target cell, then it will always be right for the relevant user (unless they disable macros)


How would that look in VBA? And would that go on every sheet that the code needs to be pulled from? Would this be a module?
 
Last edited:
Upvote 0
something like, on the worksheet >

Code:
Private Sub Worksheet_Activate()
ActiveSheet.Range("A1") = Environ("username")
End Sub
 
Upvote 0
something like, on the worksheet >

Code:
Private Sub Worksheet_Activate()
ActiveSheet.Range("A1") = Environ("username")
End Sub


This code did not work when the workbook opened. Any additional thoughts on this?
 
Upvote 0
it should work on worksheet change not workbook activate
you could on workbook open just run the code to point to the sheet you want first and then..

sheets("your first sheet").select
sheets("your first sheet").Range("A1") = Environ("username")

or


with sheets("your first sheet")
.select
.Range("A1") = Environ("username")
end with
 
Upvote 0

Forum statistics

Threads
1,215,183
Messages
6,123,522
Members
449,103
Latest member
Michele317

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