I have the code below that is obtaining the employee name from the A1 cell and setting it as part of the filename. The problem is the value in the excel sheet is written as 'first name last name'
Is there anyway I can format the value as 'last name, first name' using VBA?
Sub MyMacro()
Dim Employee As String
Dim FileN As String
Employee = Sheets("Sheet1").Range("A1").Value
FileN = Employee & "_appraisals_" & Format(Range("A2"), "yyyy.mmm")
ChDir "C:\Users\filepath\Desktop\PDFTest"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=FileN, Quality:=xlQualityStandard _
, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False
End Sub
CodePudding user response:
Yes, there is. Use below code
Employee = Split(Employee, " ")(1) & " " & Split(Employee, " ")(0)
Note: I assume first and last name is space delimited.