It sounds like you need either a series of nested loops (For..Next), a recursive
routine, or a combination of iteration & recursion. I've written a few routines
like this before and am glad to help if I can. When you test a set of numbers,
what is the test? What determines if the set passes or fails?