View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Floyd Floyd is offline
external usenet poster
 
Posts: 7
Default Excel Programming

Thanks Bob but I was looking for a different answer.

If N= 30, then
something like that...

Your help would be greatly appreciated

"Bob Bridges" wrote:

Interesting problem. I can think of a few different ways to do it, but
nothing very elegant in VBA; another language would make it easier. On the
assumption that your numbers are not necessarily consecutive sequences every
time, let's try them as character strings delimited by spaces. I'll fill a
sample starting string with consecutive numbers, but I don't know how you
should get yours.

StrFm = ""
For iv = 5 to 12
StrFm = StrFm & iv & " "
next iv

Now you have a string consisting of "5 6 7 8 9 10 11 12 ", your numbers
(well, mine) with a space after each one. If you want to pick every 3rd
number as you describe below, you could run through that string multiple
times, each time peeling one number from the front of the string and moving
it to the back end, picking out every third number to transfer to the target
string instead:

StrTo = ""
Count = 3
Do
ps = InStr(StrFm, " ") 'find the next space
ThisNbr = Left(StrFm, ps) 'copy the next number...
StrFm = Mid(StrFm, ps + 1) '...and remove it from the front of the list
Count = Count - 1
If Count = 0 Then
StrTo = StrTo & ThisNbr 'we'll take this one
Count = 3 'start the counter over
Else
StrFm = StrFm & ThisNbr 'put it back and get another
End If
Loop While StrFm < ""

I just tested this code and it seems to generate the list according to your
logic. It's not pretty, though. Maybe a collection would be a bit more
elegant.

--- "Floyd" wrote:
What is the formula to arrange a set of numbers by a specific number?

Example: I have 1, 2, 3, 4, 5, 6, 7, 8, and 9. I would like to arrange them
by (3) every third number. The answer would be 3, 6, 9, 4, 8, 5, 2, 7,
and then 1.