View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T[_8_] Peter T[_8_] is offline
external usenet poster
 
Posts: 88
Default Extract segments of an array

"Tatsujin" wrote in message
My array of strings is already sorted from A to Z:

mySort(1) = "apples"
mySort(2) = "apricot"
mySort(3) = "banana"
mySort(4) = "beans"
mySort(5) = "bread"
mySort(6) = "donuts"
'... etc, etc..
mySort(38) = "zuchini"

Is there an easy function that can copy any alphabetical segment of the
array into a new array?

For example, if I give the function input "B", it should create this new
array:

myarray = Array("banana", "beans", "bread")


Dim i as Long, k as Long
Dim myarray () As String
' code
ReDim myarray (1 To 3) ' or 0 to 2
For i = 3 To 5
k = k + 1
myarray (k) = mySort(i)
Next

There are other efficient ways to copy entire or part arrays but complicated
with string arays. The worksheet Index function would do it but not
efficient and much faster to loop as above.

Peter T