Update User.Name with suffix when neccessary

Livin404

Well-known Member
Joined
Jan 7, 2019
Messages
743
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Greetings, I have a VBA which works "nearly" perfect. However there are occasions, on certain names it only displays the surname. For example the official username is: " WHITESIDE, SHERIDAN U A1C IATA AMC 437 ERA/TROP" with the my current VBA will give me "UPDATED BY: WHITESIDE" What I hope to get is UPDATED BY: A1C WHITESIDE. Some of the names work fine but others it just leaves the surname. Another example may have a username listed as "WHITESIDE, SHERIDAN U JR TSgt USAF IATA 437 APS/TROP." where I hope it will yield UPDATED BY: TSGT WHITESIDE. Please note for the suffix it would be along the lines of JR, SR, III, IV etc.

My current VBA is:

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, "GS-05", "MR")
    Title = ""
        For Each x In Array("MR ", "SrA ", "SSgt ", "A1C ", "TSgt ", "Amn ")
        If InStr(WorkName, x) > 0 Then
            Title = x
            Exit For
        End If
    Next x
    Range("A" & LastRow + 3).Value = "UPDATED BY: " & UCase(Title) & UCase(Split(WorkName, ",")(0))
      End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Greetings, I have a VBA which works "nearly" perfect. However there are occasions, on certain names it only displays the surname. For example the official username is: " WHITESIDE, SHERIDAN U A1C IATA AMC 437 ERA/TROP" with the my current VBA will give me "UPDATED BY: WHITESIDE" What I hope to get is UPDATED BY: A1C WHITESIDE. Some of the names work fine but others it just leaves the surname. Another example may have a username listed as "WHITESIDE, SHERIDAN U JR TSgt USAF IATA 437 APS/TROP." where I hope it will yield UPDATED BY: TSGT WHITESIDE. Please note for the suffix it would be along the lines of JR, SR, III, IV etc.

My current VBA is:

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, "GS-05", "MR")
    Title = ""
        For Each x In Array("MR ", "SrA ", "SSgt ", "A1C ", "TSgt ", "Amn ")
        If InStr(WorkName, x) > 0 Then
            Title = x
            Exit For
        End If
    Next x
    Range("A" & LastRow + 3).Value = "UPDATED BY: " & UCase(Title) & UCase(Split(WorkName, ",")(0))
      End Sub
There was a small adjustment, and everything seems to be working properly now. Thank you,

VBA Code:
Sub find_last_plus_3()
Dim LastRow As Long
Dim wName As String, wSurame As String, Title As String
Dim x As Variant
LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
 
wName = Replace(Application.UserName, "GS-05", "MR")
wSurname = UCase(Split(wName, ",")(0))

For Each x In Array("MR ", "SrA ", "SSgt ", "A1C ", "TSgt ", "Amn ")
    If InStr(wName, x) > 0 Then
        Title = UCase(x)
        Exit For
    End If
Next x
Range("A" & LastRow + 3).Value = "UPDATED BY: " & Title & wSurname
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,022
Messages
6,122,726
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