Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 905
Default How to assign Spit to 1-origined array?

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default How to assign Spit to 1-origined array?

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.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default How to assign Spit to 1-origined array?

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.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 905
Default How to assign Spit to 1-origined array?

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


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


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

"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.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 905
Default How to assign Spit to 1-origined array?

"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.






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default 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.




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
spit & sum comma delimted value Francois Taljaard Excel Discussion (Misc queries) 10 September 8th 08 09:42 AM
Assign Values to array Jeff Excel Discussion (Misc queries) 14 July 15th 08 06:06 PM
Assign formula array in vba ManOnBar Excel Programming 0 July 21st 05 08:11 PM
How do I assign values to an array? Skyway[_2_] Excel Programming 14 February 29th 04 01:22 AM
Possible to assign an array to a SeriesCollection Stephen Boulet Excel Programming 2 November 13th 03 06:36 PM


All times are GMT +1. The time now is 11:25 AM.

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"