Appear username when open worksheet

noelmus

Board Regular
Joined
Dec 30, 2018
Messages
105
I have a worksheet named "MINE" and need that when I open it my username appears in cell A1. I need that my username will be full name, example Tony Smith.

Thanks in advance
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
I have a worksheet named "MINE" and need that when I open it my username appears in cell A1. I need that my username will be full name, example Tony Smith.

Thanks in advance

Hi,
I assume that you want to have appeared excel application user name. For this use the following:
Code:
Sub AppearUsrName()
Dim ws as worksheet

Set ws = worksheets("MINE")
If ActiveSheet.Name=ws.Name then
 ws.range("A1")=Application.UserName
End if

Set ws = nothing
End sub
 
Upvote 0
Hi
I tried the code in worksheet and even in workbook and nothing appeared when I opened the worksheet.
Thanks
 
Upvote 0
Sorry
It worked but you have to run it manually. I need it automatically and where I will put the code, in workbook or worksheet?
Thanks.
 
Upvote 0
So sorry. You have to go to the workbook module and type in below code. It's needed to use workbook_sheetactivate event if the macro is to run when you change the sheet to MINE.
Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim ws as worksheet

Set ws = worksheets("MINE")
If ActiveSheet.Name=ws.Name then
 ws.range("A1")=Application.UserName
End if

Set ws = nothing

End Sub
 
Upvote 0
If the previous code won't work try this. This one should-the previous one should work too. I'm writing the code for you on my mobile so I'm not able to debug the code I'm writing.
Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim ws as worksheet

Set ws = worksheets("MINE")
If Sh.Name=ws.Name then
 ws.range("A1")=Application.UserName
End if

Set ws = nothing

End Sub
 
Upvote 0
Happy to help :)
Thanks for your feedback :)
 
Upvote 0

Forum statistics

Threads
1,223,723
Messages
6,174,107
Members
452,544
Latest member
aush

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