Alter Application.Username

Livin404

Well-known Member
Joined
Jan 7, 2019
Messages
743
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Greetings I have the following VBA which I can get the following results. Ranks and etc. are arbitrary. Which I get from: I would like to adjust the username, to make it more concise.

VBA Code:
Sub find_last_plus_3()
LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
Range("A" & LastRow + 3).Value = "UPDATED BY:" & " " & Application.UserName
End Sub

REVIEWED BY: WHITESIDE, SHERIDAN U ESQ-07 ERAU UAA 437 CHS/IATA
REVIEWED BY: WHITESIDE, SHERIDAN U CAPT ERAU UAA 437 CHS/IATA
REVIEWED BY: WHITESIDE, SHERIDAN U MAJ ERAU UAA 437 CHS/IATA

If at all possible I would like the end result to be.
UPDATED BY: MR WHITESIDE
UPDATED BY: CAPT WHITESIDE
UPDATED BY: MAJ WHITESIDE

I just would like to keep the surname drop everything else, but move that block of letters ESQ-07 and change it to a MR (no period). Most important there are only two in the organization that have this title. The rest will have a Rank it will be either 3 or 4 letters; for example, CAPT or MAJ. Any assistance would be great. Thank you
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
I assume Sheridan U is the first name, middle initial? Will everyone have an initial? It might be easier to look for a list of the possible titles. Try:

VBA Code:
Sub find_last_plus_3()
Dim LastRow As Long, WorkName As String, Title As String, x As Variant

    LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
    WorkName = Replace(Application.UserName, "ESQ-07", "MR")
    Title = ""
    For Each x In Array("MR ", "CAPT ", "MAJ ", "GEN ", "PVT ")
        If InStr(WorkName, x) > 0 Then
            Title = x
            Exit For
        End If
    Next x
    Range("A" & LastRow + 3).Value = "UPDATED BY: " & Title & Split(WorkName, ",")(0)
End Sub

Although this could also have issues if you have a name that contains one of those titles, like
GENERO, HOLLY PVT
 
Upvote 0
Solution
That was absolutely perfect. It seems to be exactly what I was after. Thank you so much!
 
Upvote 0

Forum statistics

Threads
1,215,025
Messages
6,122,731
Members
449,093
Latest member
Mnur

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