View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
davidm davidm is offline
external usenet poster
 
Posts: 1
Default Need code to pair off numbers


I have been grappling with an idea of setting off pairs (even clusters)
of numbers *using code *as in (1,2,3); (4,5,6); (7,8,9) ... (58,59,60)
for a data range 1-60 in this case. This is easily accomplished on
worksheet but I need results that can be stored in, and retrieved from
an array. In the generalized case, I would want the code to trussle up
n elements, where n can be any number not more than the count of
elements in the data range population set.

Thus, in the current instance, the code should be adaptable to draw out
(1,2);(3,4);(5,6)... where n=2 as well as (1,2,3,4,5), (6,7,8,9,10) ...
where n=5. The attempted code below further illustrates what I am
groping for.

Sub Cluster3Elements()
Dim arr()
n = 0
For i = 1 To 60 Step 3
ReDim Preserve arr(n)
arr(i) = i & "," & i + 1 & "," & i + 2 === Subscript Out of range
error
n = n + 1
Next
'test
For j = LBound(arr) To UBound(arr)
Debug.Print arr(j)
Next
End Sub

TIA.

Davidm


--
davidm
------------------------------------------------------------------------
davidm's Profile: http://www.excelforum.com/member.php...o&userid=20645
View this thread: http://www.excelforum.com/showthread...hreadid=513059