How to assign Spit to 1-origined array?
...Split..Is there a straight-forward to cause the first index to be
one?
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
On 12/23/2009 8:19 PM, Joe User wrote:
"Rick Rothstein" wrote:
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 -----
"Rick Rothstein" wrote in message
...
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, ",")
--
Rick (MVP - Excel)
"Rick Rothstein" wrote in
message ...
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.
--
Rick (MVP - Excel)
"Joe User" <joeu2004 wrote in message
...
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.
|