Hi Folks,
Another thing I can't quite understand what Excel is doing...
I have a UDF that I think i originally found here on Mr. Excel so it was not me that wrote this skilled piece of code.
This code works perfectly fine on my desktop computer running O365 and takes a 1D range list of words and makes combinations of the words without repeats.
When i take the same file to my laptop that is also running O365 with all the same VBA references, etc, it doesn't work and i get the following error, can't find project or library.
It looks like it is because I don't have Dim rng1, Dim g, etc for example below. When I dim rng1 as Varient, Dim g as Single and any other variables, then it works.
What I struggle to understand is, why would the workbook and macros work on one computer without these and a copy of the same exact file not work on another machine?
There are other macros in other modules as well, but they are also in both copies of the workbook laptop vs. desktop.
Thank you for your insight!
When I take the exact same file to my laptop however,
Another thing I can't quite understand what Excel is doing...
I have a UDF that I think i originally found here on Mr. Excel so it was not me that wrote this skilled piece of code.
This code works perfectly fine on my desktop computer running O365 and takes a 1D range list of words and makes combinations of the words without repeats.
When i take the same file to my laptop that is also running O365 with all the same VBA references, etc, it doesn't work and i get the following error, can't find project or library.
It looks like it is because I don't have Dim rng1, Dim g, etc for example below. When I dim rng1 as Varient, Dim g as Single and any other variables, then it works.
What I struggle to understand is, why would the workbook and macros work on one computer without these and a copy of the same exact file not work on another machine?
There are other macros in other modules as well, but they are also in both copies of the workbook laptop vs. desktop.
Thank you for your insight!
When I take the exact same file to my laptop however,
VBA Code:
Public result() As Variant
Function Combinations(rng As Range, n As Single)
Dim b As Single
rng1 = rng.Value
b = WorksheetFunction.Combin(UBound(rng1, 1), n)
ReDim result(b, n - 1)
Call Recursive(rng1, n, 1, 0, 0)
For g = 0 To UBound(result, 2)
result(UBound(result, 1), g) = ""
Next g
Combinations = result
End Function
Function Recursive(r As Variant, c As Single, d As Single, e As Single, h As Single)
Dim f As Single
For f = d To UBound(r, 1)
result(h, e) = r(f, 1)
If e = (c - 1) Then
For g = 0 To UBound(result, 2)
result(h + 1, g) = result(h, g)
Next g
h = h + 1
Else
Call Recursive(r, c, f + 1, e + 1, h)
End If
Next f
End Function