Excel VBA Custom Function

The following post illustrates how to create a custom function in Excel, using a VBA module.  In particular, I will create two functions that parse a cell containing a full name (First and Last) into two separate cells.  I frequently need to run through this process, so I figured it would be a good way to demonstrate how to utilize an Excel VBA Custom Function in practice.

Excel VBA Custom Function – Setup

I have the following list of names:

Excel VBA Custom Function

What I would like is two additional columns, containing the First and Last names separately.  This is a task that can be done via Excel built-in functions, but for demonstration purposes, I am going to create two custom functions using VBA.

Open a new module and insert the following code:

Go back into your worksheet and add column headers “First Name” and “Last Name”, in cells B1 and C1 respectively.

In cell B2, add the following formula:  =GetFirstName(A2), then copy it down for the entire range in column A

Excel VBA Custom Function

In cell C2, add the following formula:  =GetLastName(A2), then copy it down for the entire range in column A

Excel VBA Custom Function

You now have the two new columns you need, and two custom functions to accomplish the task.

Excel VBA Custom Function

Again, this is a simple string manipulation that can easily be achieved using Excel built-in functions, but I wanted to show simple, but practical example on how to create custom functions in Excel using VBA.

 

 

 

Additional Content

Check out more examples by visiting my Home Page

Here you will find topics covering  Qlikview  SQL Server  Excel VBA

 

 

Leave a Comment