Excel formula to rearrange LastName, Firstname MiddleInitial to FirstName Lastname -
i need formula rearrange names. i've found lots of formulas work in cases, none can handle of cases encounter.
briefly, here list of names, , desired output:
original names desired output john, james j james john junior, lake lake junior mitchel, fields m fields mitchel rothschild jr., michael k michael rotschild sally, sue l sue sally rinkel, michael michael rinkel rivel, nicholas l nicholas rivel hurwitz sr., susan susan hurwitz the formula have far is: =trim(proper(trim(if(iserror(find(",",a1,1)),a1,mid(a1,find(",",a1,1)+1,if(iserror(find(" ",a1,find(",",a1,1)+2)),len(a1),find(" ",a1,find(",",a1,1)+2))-find(",",a1,1))))&" "&left(a1,if(iserror(find(",",a1,1)),len(a1),find(",",a1,1)-1))))
its cobbled other formulas have found, , eliminates middle initials if present, not sr. or jr.'s if present.
there many nuances parsing names think have covered possibilities, there new ones coming up. if keep user defined formula (aka udf), can add new coding processes meet new problems.
public function fcn_first_last_name(snam string) dim stmp string, v long, vdels variant, vnams variant stmp = application.trim(snam) vdels = array(" jr.", " sr.", " iii", " ii") stmp = replace(stmp, chr(160), chr(32)) v = lbound(vdels) ubound(vdels) stmp = replace(stmp, vdels(v), vbnullstring, compare:=vbtextcompare) next v if asc(mid(stmp, len(stmp) - 1, 1)) = 32 stmp = trim(left(stmp, len(stmp) - 1)) vnams = split(stmp, chr(44)) if cbool(ubound(vnams)) fcn_first_last_name = vnams(ubound(vnams)) & chr(32) & vnams(lbound(vnams)) else fcn_first_last_name = vnams(ubound(vnams)) end if end function that should started. should prove learning experience add new routines cover new difficulties.
once have in vba code module sheet, use other worksheet formula. example:

Comments
Post a Comment