View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Bob Bridges[_2_] Bob Bridges[_2_] is offline
external usenet poster
 
Posts: 257
Default Excel Programming

Not sure what you mean. The below algorithm does indeed
arrange a set of numbers, choosing every third one, and it
seems to match the example you gave. Do you mean you
wanted to know how to do it to a sequence of numbers from
1 to 30? The below code works for that, after you modify the
initial startup loop to match your specs. Do you mean you
want to be able to pick every 30th number, not just every 3rd?
But the below logic does that too, if only you modify the way
Count is handled. What 'N' is supposed to be set to 3?

--- "Floyd" wrote:
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 < ""

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