How to assign Spit to 1-origined array?

J

Joe User

Currently, I use Split as follows:

Dim w, mylist as string
w = Split(mylist)

That creates an array with the first index (LBound) of zero.

Is there a straight-forward to cause the first index to be one?

(I don't know the number of "words" in mylist a priori.)

I am using Excel 2003 SP3 with VBA 6.5.1024.
 
R

Rick Rothstein

No, Split is unusual in that it **always** returns a zero-based array even
if you use "Option Base 1" to force the lower bound of arrays to be one.
 
R

Rick Rothstein

Well, let my take back the "No" part of my response... you can "fake it" if
you want... just add the delimiter to the front of the text being split...
you will still get a zero-based array, but the zero element will be the
empty string and the first real element will be at index value 1. So, just
change your statement to this...

w = Split(" " & mylist)

where I used a space because Split uses a space as the delimiter by default
when no delimiter is specified. If you were were working with a comma
delimited list, then your statement would be this...

w = Split("," & mylist, ",")
 
J

Joe User

Rick Rothstein said:
No, Split is unusual in that it **always** returns
a zero-based array

Thanks for the confirmation. No big deal; just curious.


----- original message -----
 
J

Joe User

Rick Rothstein said:
Well, let my take back the "No" part of my response...
you can "fake it" if you want... [....]
w = Split(" " & mylist)

Well, duh! I must be getting old :).


----- original message -----
 
D

Dana DeLouis

...Split..Is there a straight-forward to cause the first index to be

Hi. Here's a common workaround that I use:

Sub Demo()
Dim s, v
s = "a,b,c,d,e"
v = Split(s, ",")
v = T2(v)
End Sub


Function T2(v)
'// Double Transpose
With WorksheetFunction
T2 = .Transpose(.Transpose(v))
End With
End Function

= = = = = = = = = = =
HTH :>)
Dana DeLouis



Rick Rothstein said:
Well, let my take back the "No" part of my response...
you can "fake it" if you want... [....]
w = Split(" " & mylist)

Well, duh! I must be getting old :).


----- original message -----
 

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

Top