View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Bill Renaud Bill Renaud is offline
external usenet poster
 
Posts: 417
Default Splitting strings, error subscript out of range

Maybe one of the last parts of the input string is not present (i.e.
'DateIssue' or 'Date Served'). Since you are only returning FirstName and
LastName, you could use:

Private Function SplitMe(strToSplit As String)
Dim vntX As Variant

vntX = Split(strToSplit, ",")

TxtFirstName = vntX(0) ' FirstName
TxtLastName = vntX(1) ' Last Name

SplitMe = TxtFirstName & "," & TxtLastName
End Function

You should check Ubound(vntX) to be sure that it is at least 1, as Gary's
Student mentioned. You should also declare all of your variables and use
Option Explicit at the top of all code modules.
--
Regards,
Bill Renaud