Tag Archives: instr function

How To Have VBA Parse A Name String

This post was actually an answer to someone’s question on one of my videos from a few years back.

https://www.youtube.com/watch?v=UspqR0g4XyU

The comment was:

How would you do this for the last name? Or second last name? How to find the space after the first space, and the space after the second space? And then, if there is no first space or there is a first space but no second space, then skip the function instead of error?

So the video was put out a few years back, and so I’m going to show you a newer way of handling this.

Here is the worksheet and a little explanation:

Basically, this is going to be one function, and one of my arguments is going to decide whether we need to parse the first name, last name, or middle name.

…And here are the answers to her questions:

How would you do this for the last name?

Or second last name?

Since that may mean “middle” name, I’m going to show that.

The following will answer these 2 questions as well:

How to find the space after the first space, and the space after the second space?

And then, if there is no first space or there is a first space but no second space, then skip the function instead of error?

Here’s the code all together:

Let me know if you have any questions, and make sure you share this with someone else.

Facebooktwittergoogle_plusredditpinterestlinkedinmail
READ MORE