VBA command similar to COBAL Inspect

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a VBA command or commands that perform the same function as the
COBOL Inspect. It would be usefull for separating first name from last name
when there is a space between them. Thanks for your help!!
 
If I had:

emp_name = "Jason Lepack"

and first names and last names always had only one space between them
then I would do this:

first_name = left(emp_name, instr(1,emp_name,' ')-1)
last_name = mid(emp_name, len(first_name)+2)

Another useful function is right as well as instrrev.

Cheers,
Jason Lepack
 
In
Jason Lepack said:
If I had:

emp_name = "Jason Lepack"

and first names and last names always had only one space between them
then I would do this:

first_name = left(emp_name, instr(1,emp_name,' ')-1)
last_name = mid(emp_name, len(first_name)+2)

Another useful function is right as well as instrrev.

And let's not forget (in versions from 2000 forward) the Split function.

Dim aNames() As String

aNames = Split(emp_name)
first_name = aNames(0)
last_name = aNames(1)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top