I want to segregate singles, doubles and triples from a string.
e.g. (2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 - 11 , 12 - 14 , 15 - 16 , 17 , 18 , 19 , 20 , 21 - 22 , 23 - 25 , 26 , 27 , 28 , 29 , 30 , 31 , 32 , 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40)
Result should be
Singles - (2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ,17 , 18 , 19 , 20 ,26 , 27 , 28 , 29 , 30 , 31 , 32 , 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40)
Doubles - (10 - 11 ,15 - 16 , 21 - 22 )
Triples - (12 - 14 ,23 - 25 )
With below code i get collection of data but how to write in cell??
e.g. (2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 - 11 , 12 - 14 , 15 - 16 , 17 , 18 , 19 , 20 , 21 - 22 , 23 - 25 , 26 , 27 , 28 , 29 , 30 , 31 , 32 , 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40)
Result should be
Singles - (2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ,17 , 18 , 19 , 20 ,26 , 27 , 28 , 29 , 30 , 31 , 32 , 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40)
Doubles - (10 - 11 ,15 - 16 , 21 - 22 )
Triples - (12 - 14 ,23 - 25 )
With below code i get collection of data but how to write in cell??
Code:
Sub x()
Dim s AsStringDim a()AsStringDim a2()AsStringDim v AsVariantDim colSingles AsNew CollectionDim colDoubles AsNew CollectionDim colTriples AsNew Collection
s ="2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 - 11 , 12 - 14 , 15 - 16 , 17 , 18 , 19 , 20 , 21 - 22 , 23 - 25 , 26 , 27 , 28 , 29 , 30 , 31 , 32 , 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40"
a = Split(s,",")
ForEach v In a
If InStr(1, v,"-")=0Then
colSingles.Add v,CStr(v)Else
a2 = Split(v,"-")If a2(1)- a2(0)=1Then
colDoubles.Add v,CStr(v)Else
colTriples.Add v,CStr(v)EndIfEndIf
Next v
EndSub