View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
scattered[_5_] scattered[_5_] is offline
external usenet poster
 
Posts: 4
Default Find Combinations

On Monday, June 29, 2015 at 8:33:46 PM UTC-4, Bruno Campanini wrote:
scattered has brought this to us :

Hope that helps
-scattered

Ok, very nice piece of code! Thank you very much.
If works perfectly in less than 1/3 sec and - very important thing -
it is not necessary to order both myrow and myrange LeftToRight ASC.

May I make a comment...
Why:
ReDim matches(1 To n)
For i = 1 To n
matches(i) = 0
Next i

ReDim matches(1 To n)
OR
ReDim matches(1 To n) As Integer | Long
is enough... isn't?

Bruno


Glad you could use it. I had fun writing it.

I have a strong preference for using variants to pass arrays to or from
functions/subs. For one thing -- it is somewhat idiomatic if you consider
the way built-in functions like Split() and Join() accept or return variant
arrays. For another thing -- it is easier to use variant arrays to transfer
data between VBA and the spreadsheet. In my code, I initially didn't include
that initialization loop for matches. But when I ran it matches(6) was Empty
rather than 0, and the way I was building up the report string in the test code
caused this empty value to be converted into the empty string rather than to 0.
This caused the last line to look like

Combos of size 6 =

with nothing to the right of the equals sign. Hence the explicit initialization
to 0.

-scattered