Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Splitting strings, error subscript out of range

The vntx(0)


Private Function SplitMe(strToSplit As String)
Dim vntX As Variant
vntX = Split(strToSplit, ",")
TxtFirstName = vntX(0) ' FirstName
TxtLastName = vntX(1) ' Last Name
CBOMoFa = vntX(2) ' Mother/Father
TxtChild = vntX(3) ' of Child
TxtIssued = vntX(4) ' DateIssue
TxtServed = vntX(5) ' Date Served

SplitMe = TxtFirstName & "," & TxtLastName
End Function

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Splitting strings, error subscript out of range

Insert a
MSGBOX(UBOUND(vntX)) to make sure all the parts are there.
--
Gary''s Student - gsnu2007a


" wrote:

The vntx(0)


Private Function SplitMe(strToSplit As String)
Dim vntX As Variant
vntX = Split(strToSplit, ",")
TxtFirstName = vntX(0) ' FirstName
TxtLastName = vntX(1) ' Last Name
CBOMoFa = vntX(2) ' Mother/Father
TxtChild = vntX(3) ' of Child
TxtIssued = vntX(4) ' DateIssue
TxtServed = vntX(5) ' Date Served

SplitMe = TxtFirstName & "," & TxtLastName
End Function


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Splitting strings, error subscript out of range

On Nov 8, 3:08 pm, Gary''s Student
wrote:
Insert a
MSGBOX(UBOUND(vntX)) to make sure all the parts are there.
--
Gary''s Student - gsnu2007a



" wrote:
The vntx(0)


Private Function SplitMe(strToSplit As String)
Dim vntX As Variant
vntX = Split(strToSplit, ",")
TxtFirstName = vntX(0) ' FirstName
TxtLastName = vntX(1) ' Last Name
CBOMoFa = vntX(2) ' Mother/Father
TxtChild = vntX(3) ' of Child
TxtIssued = vntX(4) ' DateIssue
TxtServed = vntX(5) ' Date Served


SplitMe = TxtFirstName & "," & TxtLastName
End Function- Hide quoted text -


- Show quoted text -


it shows that they are all there (5)

  #4   Report Post  
Posted to microsoft.public.excel.programming
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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default Splitting strings, error subscript out of range

The vntx(0)

Why did you write the above in your original post?

Private Function SplitMe(strToSplit As String)
Dim vntX As Variant
vntX = Split(strToSplit, ",")
TxtFirstName = vntX(0) ' FirstName
TxtLastName = vntX(1) ' Last Name
CBOMoFa = vntX(2) ' Mother/Father
TxtChild = vntX(3) ' of Child
TxtIssued = vntX(4) ' DateIssue
TxtServed = vntX(5) ' Date Served

SplitMe = TxtFirstName & "," & TxtLastName
End Function


There is a lot you are not telling us. All those variables you are assigning
things to... Where are the Dim'med at? Do you have vntX Dim'med elsewhere?
Are you actually making it through the function and dying elsewhere? For
this latter question, put a breakpoint on the End Function line and run your
code... do you make it to the breakpoint or not? If not, put a breakpoint on
the Split statement line and then press F8 until your code dies... what line
did it die on? Can you show us the formula (your function is a UDF, right?)
you are using to call the function (in particular, I'm interested in the
original text you are trying to split). We would also be interested in any
other details about what you are doing that you think may impact your use of
the function.

Rick



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Splitting strings, error subscript out of range

On Nov 9, 2:34 am, "Rick Rothstein \(MVP - VB\)"
wrote:
The vntx(0)


Why did you write the above in your original post?

Private Function SplitMe(strToSplit As String)
Dim vntX As Variant
vntX = Split(strToSplit, ",")
TxtFirstName = vntX(0) ' FirstName
TxtLastName = vntX(1) ' Last Name
CBOMoFa = vntX(2) ' Mother/Father
TxtChild = vntX(3) ' of Child
TxtIssued = vntX(4) ' DateIssue
TxtServed = vntX(5) ' Date Served


SplitMe = TxtFirstName & "," & TxtLastName
End Function


There is a lot you are not telling us. All those variables you are assigning
things to... Where are the Dim'med at? Do you have vntX Dim'med elsewhere?
Are you actually making it through the function and dying elsewhere? For
this latter question, put a breakpoint on the End Function line and run your
code... do you make it to the breakpoint or not? If not, put a breakpoint on
the Split statement line and then press F8 until your code dies... what line
did it die on? Can you show us the formula (your function is a UDF, right?)
you are using to call the function (in particular, I'm interested in the
original text you are trying to split). We would also be interested in any
other details about what you are doing that you think may impact your use of
the function.

Rick


There is alot, i havent said, for instance this is the only split
function and vntX that i have, these variables are assigned
I have set the values to text boxes and a combobox Im still very new
to "programming" so i really dont know any of the tricks, and my code
is really bad looking, basically what i was trying to do with this,

Private Sub CmdEdit_Click()
Dim strNames As String
Dim vntX as Variant
If CBONames.Text = "" Then
MsgBox "Select a Name Please"
End If
If CBONames.Text < "" Then
strNames = GetInfo(CBONames.Text)
End If
End Sub


Private Function GetInfo(MyTxtName As String)
Dim Tester As String
Dim Thistest As String
ActiveSheet.Unprotect Password:="g45721"
Thistest = Range("A5:AX4500").Find(LblName,
LookIn:=xlValues).Offset(0, 25)
Tester = SplitMe(Thistest)
If MyTxtName = Tester Then
GetInfo = Thistest
End If

Private Function SplitMe(strToSplit As String)
Dim vntX As Variant
Dim First As String
Dim last As String
Dim child As String
Dim issed As String
Dim served As String
vntX = Split(strToSplit, ",")
First = vntX(0) ' FirstName
last = vntX(1) ' Last NameCBOMoFa = vntX(2) ' Mother/Father
SplitMe = First & "," & last
End Function

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Runtime Error - Subscript out of range despite On Error statement DoctorG Excel Programming 3 July 28th 06 03:56 PM
Subscript out of range error - save copy error bg18461[_16_] Excel Programming 2 June 13th 06 04:53 PM
Subscript out of range error - save copy error bg18461[_15_] Excel Programming 1 June 13th 06 04:36 PM
Subscript out of range (Error 9) John in Surrey Excel Programming 1 January 11th 06 12:42 PM
Type Mismatch error & subscript out of range error Jeff Wright[_2_] Excel Programming 3 May 14th 05 07:14 PM


All times are GMT +1. The time now is 06:51 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"