Application.Username modification not working as expected

michaeltsmith93

Board Regular
Joined
Sep 29, 2016
Messages
83
I'm using the following to convert Application.Username which is formatted "Last, First" to "First Last". For my name, it is working, but for a colleague it is not. I am baffled. The result for my colleague is "h, John Smith". I have had her select all and retype it, and it's still not working. Thoughts? I don't want to use Environ because it's variable at my company.

Code:
FullName = Application.UserName
FirstName = Right(FullName, InStr(1, FullName, " ", vbTextCompare) + 1)
LastName = Left(FullName, InStr(1, FullName, ",", vbTextCompare) - 1)
FirstLast = FirstName & " " & LastName
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
What is the Username to begin with?
 
Upvote 0
That's not going to give "h, John Smith" ;)

but try
Code:
FirstName = Right(FullName, Len(FullName) - InStr(1, FullName, " ", vbTextCompare) + 1)
 
Upvote 0
Haha right you are! You see it's pulling the last letter and the comma though.

I'm having her try it now. Will let you know shortly. This is so bizarre. Clever solution you came up with, using the correctly functioning LastName.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,488
Messages
6,125,092
Members
449,206
Latest member
ralemanygarcia

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