Pages

How to setup and use an user-defined function.


     First you need to write a little vba to create a function that you want to use on a regular basis. This could be anything mundane that you do that can be simplified by using code. Below I've written a little code that will parse a last name from a name field that is set up: last name, first name.

Public Function LastNameParse(Name As String)
Dim lpos As Integer
lpos = InStr(1, Name, ",")
LastNameParse = Left(Name, lpos - 1)
End Function

     This function finds the position of the comma that is separating the last name from the first name and then trims out the comma and first name, thus, leaving only the last name.

Below is how you can now use your new function:
 
First go find your function.
 


Next Select the cell that you want to parse from.
 click "ok" and you're finished.

Here are my results:
  

No comments:

Post a Comment

Thanks for leaving a comment.