Search

Thursday, August 25, 2005

VBA Code to trim everything EXCEPT the last text string in a cell


'To use this UDF push Alt+F11 and go Insert>Module and paste in the code.
Push Alt+Q and save. The Function will appear under "User Defined" in the
Paste Function dialog box (Shift+F3). Use the Function as shown in the
graphic example below.
Function ReturnLastWord(The_Text As String)
Dim stGotIt As String
i = 1
Do Until stGotIt Like (" *")
stGotIt = Right(The_Text, i)
i = i + 1
Loop
ReturnLastWord = Trim(stGotIt)
End Function