VBA command similar to COBAL Inspect

V

vtj

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!!
 
J

Jason Lepack

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
 
D

Dirk Goldgar

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)
 
Top