This article was previously published under Q210054
Moderate: Requires basic macro, coding, and interoperability skills.
Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.
View products that this article applies to.
Option Explicit
Function NFormat(First As Variant, Middle As Variant, Last As _
Variant, Style As Variant)
On Error GoTo Err_NFormat
Dim iFirst As Variant, iMiddle As Variant, iLast As Variant
Dim NewName As String
iFirst = IIf(Len(First),Left(First, 1) + IIf(Len(First) = 1, " ", _
". "), "")
iMiddle = IIf(Len(Middle),Left(Middle, 1) + IIf(Len(Middle) = 1, _
" ", ". "),"")
iLast = IIf(Len(Last),Left(Last, 1) + IIf(Len(Last) = 1, " ", ". ") _
, "")
Select Case Style
Case "0", "FML"
NewName = First & " " & (Middle + " ") & Last
Case "1", "FIL"
NewName = First & " " & iMiddle & Last
Case "2", "IIL"
NewName = iFirst & iMiddle & Last
Case "3", "LFM"
NewName = Last & ", " & First & (" " + Middle)
Case "4", "LFI"
NewName = Last & ", " & First & (" " + iMiddle)
Case "5", "LII"
NewName = Last & ", " & iFirst & iMiddle
Case "6", "FL"
NewName = First & " " & Last
Case "7", "FI"
NewName = First & " " & iLast
Case "8", "LF"
NewName = Last & ", " & First
Case "9", "LI"
NewName = Last & ", " & iFirst
Case "10", "III"
NewName = iFirst & iMiddle & iLast
Case "11", "II"
NewName = iFirst & iLast
Case Else
NewName = ""
End Select
NFormat = Trim(NewName)
Exit Function
Err_NFormat:
NFormat = "#Error"
End Function
? NFormat("Nancy","Anne","Davolio",4)
NFormat([First],[Middle],[Last],[Style])
Where Displays [Style]=0 Nancy Anne Davolio [Style]=1 Nancy A. Davolio [Style]=2 N. A. Davolio [Style]=3 Davolio, Nancy Anne [Style]=4 Davolio, Nancy A. [Style]=5 Davolio, N. A. [Style]=6 Nancy Davolio [Style]=7 Nancy D. [Style]=8 Davolio, Nancy [Style]=9 Davolio, N. [Style]=10 N. A. D. [Style]=11 N. D.
Keywords: KB210054, kbusage, kbprogramming, kbhowto