Got any Excel/VBA Questions? Free Excel Help.
This UDF will extract the last word from a Text String.
The Code
Function ReturnLastWord(The_Text As String) Dim stGotIt As String '''''''''''''''''''''''''''''''''''''''''' 'Written by OzGrid Business Applications 'www.ozgrid.com 'Extracts the LAST word from a text string '''''''''''''''''''''''''''''''''''''''''' stGotIt = StrReverse(The_Text) stGotIt = Left(stGotIt, InStr(1, stGotIt, " ", vbTextCompare)) ReturnLastWord = StrReverse(Trim(stGotIt)) End Function
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.
See also Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions.
Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.